home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / meschach / meschach1.shar < prev    next >
Encoding:
Text File  |  1994-06-07  |  139.1 KB  |  5,841 lines  |  [TEXT/ttxt]

  1. # to unbundle, sh this file (in an empty directory)
  2. echo copy.c 1>&2
  3. sed >copy.c <<'//GO.SYSIN DD copy.c' 's/^-//'
  4. -
  5. -/**************************************************************************
  6. -**
  7. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  8. -**
  9. -**                 Meschach Library
  10. -** 
  11. -** This Meschach Library is provided "as is" without any express 
  12. -** or implied warranty of any kind with respect to this software. 
  13. -** In particular the authors shall not be liable for any direct, 
  14. -** indirect, special, incidental or consequential damages arising 
  15. -** in any way from use of the software.
  16. -** 
  17. -** Everyone is granted permission to copy, modify and redistribute this
  18. -** Meschach Library, provided:
  19. -**  1.  All copies contain this copyright notice.
  20. -**  2.  All modified copies shall carry a notice stating who
  21. -**      made the last modification and the date of such modification.
  22. -**  3.  No charge is made for this software or works derived from it.  
  23. -**      This clause shall not be construed as constraining other software
  24. -**      distributed on the same medium as this software, nor is a
  25. -**      distribution fee considered a charge.
  26. -**
  27. -***************************************************************************/
  28. -
  29. -
  30. -static    char    rcsid[] = "$Id: copy.c,v 1.2 1994/01/13 05:37:14 des Exp $";
  31. -#include    <stdio.h>
  32. -#include    "matrix.h"
  33. -
  34. -
  35. -
  36. -/* _m_copy -- copies matrix into new area */
  37. -MAT    *_m_copy(in,out,i0,j0)
  38. -MAT    *in,*out;
  39. -u_int    i0,j0;
  40. -{
  41. -    u_int    i /* ,j */;
  42. -
  43. -    if ( in==MNULL )
  44. -        error(E_NULL,"_m_copy");
  45. -    if ( in==out )
  46. -        return (out);
  47. -    if ( out==MNULL || out->m < in->m || out->n < in->n )
  48. -        out = m_resize(out,in->m,in->n);
  49. -
  50. -    for ( i=i0; i < in->m; i++ )
  51. -        MEM_COPY(&(in->me[i][j0]),&(out->me[i][j0]),
  52. -                (in->n - j0)*sizeof(Real));
  53. -        /* for ( j=j0; j < in->n; j++ )
  54. -            out->me[i][j] = in->me[i][j]; */
  55. -
  56. -    return (out);
  57. -}
  58. -
  59. -/* _v_copy -- copies vector into new area */
  60. -VEC    *_v_copy(in,out,i0)
  61. -VEC    *in,*out;
  62. -u_int    i0;
  63. -{
  64. -    /* u_int    i,j; */
  65. -
  66. -    if ( in==VNULL )
  67. -        error(E_NULL,"_v_copy");
  68. -    if ( in==out )
  69. -        return (out);
  70. -    if ( out==VNULL || out->dim < in->dim )
  71. -        out = v_resize(out,in->dim);
  72. -
  73. -    MEM_COPY(&(in->ve[i0]),&(out->ve[i0]),(in->dim - i0)*sizeof(Real));
  74. -    /* for ( i=i0; i < in->dim; i++ )
  75. -        out->ve[i] = in->ve[i]; */
  76. -
  77. -    return (out);
  78. -}
  79. -
  80. -/* px_copy -- copies permutation 'in' to 'out' */
  81. -PERM    *px_copy(in,out)
  82. -PERM    *in,*out;
  83. -{
  84. -    /* int    i; */
  85. -
  86. -    if ( in == PNULL )
  87. -        error(E_NULL,"px_copy");
  88. -    if ( in == out )
  89. -        return out;
  90. -    if ( out == PNULL || out->size != in->size )
  91. -        out = px_resize(out,in->size);
  92. -
  93. -    MEM_COPY(in->pe,out->pe,in->size*sizeof(u_int));
  94. -    /* for ( i = 0; i < in->size; i++ )
  95. -        out->pe[i] = in->pe[i]; */
  96. -
  97. -    return out;
  98. -}
  99. -
  100. -/*
  101. -    The .._move() routines are for moving blocks of memory around
  102. -    within Meschach data structures and for re-arranging matrices,
  103. -    vectors etc.
  104. -*/
  105. -
  106. -/* m_move -- copies selected pieces of a matrix
  107. -    -- moves the m0 x n0 submatrix with top-left cor-ordinates (i0,j0)
  108. -       to the corresponding submatrix of out with top-left co-ordinates
  109. -       (i1,j1)
  110. -    -- out is resized (& created) if necessary */
  111. -MAT    *m_move(in,i0,j0,m0,n0,out,i1,j1)
  112. -MAT    *in, *out;
  113. -int    i0, j0, m0, n0, i1, j1;
  114. -{
  115. -    int        i;
  116. -
  117. -    if ( ! in )
  118. -    error(E_NULL,"m_move");
  119. -    if ( i0 < 0 || j0 < 0 || i1 < 0 || j1 < 0 || m0 < 0 || n0 < 0 ||
  120. -     i0+m0 > in->m || j0+n0 > in->n )
  121. -    error(E_BOUNDS,"m_move");
  122. -
  123. -    if ( ! out )
  124. -    out = m_resize(out,i1+m0,j1+n0);
  125. -    else if ( i1+m0 > out->m || j1+n0 > out->n )
  126. -    out = m_resize(out,max(out->m,i1+m0),max(out->n,j1+n0));
  127. -
  128. -    for ( i = 0; i < m0; i++ )
  129. -    MEM_COPY(&(in->me[i0+i][j0]),&(out->me[i1+i][j1]),
  130. -         n0*sizeof(Real));
  131. -
  132. -    return out;
  133. -}
  134. -
  135. -/* v_move -- copies selected pieces of a vector
  136. -    -- moves the length dim0 subvector with initial index i0
  137. -       to the corresponding subvector of out with initial index i1
  138. -    -- out is resized if necessary */
  139. -VEC    *v_move(in,i0,dim0,out,i1)
  140. -VEC    *in, *out;
  141. -int    i0, dim0, i1;
  142. -{
  143. -    if ( ! in )
  144. -    error(E_NULL,"v_move");
  145. -    if ( i0 < 0 || dim0 < 0 || i1 < 0 ||
  146. -     i0+dim0 > in->dim )
  147. -    error(E_BOUNDS,"v_move");
  148. -
  149. -    if ( (! out) || i1+dim0 > out->dim )
  150. -    out = v_resize(out,i1+dim0);
  151. -
  152. -    MEM_COPY(&(in->ve[i0]),&(out->ve[i1]),dim0*sizeof(Real));
  153. -
  154. -    return out;
  155. -}
  156. -
  157. -/* mv_move -- copies selected piece of matrix to a vector
  158. -    -- moves the m0 x n0 submatrix with top-left co-ordinate (i0,j0) to
  159. -       the subvector with initial index i1 (and length m0*n0)
  160. -    -- rows are copied contiguously
  161. -    -- out is resized if necessary */
  162. -VEC    *mv_move(in,i0,j0,m0,n0,out,i1)
  163. -MAT    *in;
  164. -VEC    *out;
  165. -int    i0, j0, m0, n0, i1;
  166. -{
  167. -    int        dim1, i;
  168. -
  169. -    if ( ! in )
  170. -    error(E_NULL,"mv_move");
  171. -    if ( i0 < 0 || j0 < 0 || m0 < 0 || n0 < 0 || i1 < 0 ||
  172. -     i0+m0 > in->m || j0+n0 > in->n )
  173. -    error(E_BOUNDS,"mv_move");
  174. -
  175. -    dim1 = m0*n0;
  176. -    if ( (! out) || i1+dim1 > out->dim )
  177. -    out = v_resize(out,i1+dim1);
  178. -
  179. -    for ( i = 0; i < m0; i++ )
  180. -    MEM_COPY(&(in->me[i0+i][j0]),&(out->ve[i1+i*n0]),n0*sizeof(Real));
  181. -
  182. -    return out;
  183. -}
  184. -
  185. -/* vm_move -- copies selected piece of vector to a matrix
  186. -    -- moves the subvector with initial index i0 and length m1*n1 to
  187. -       the m1 x n1 submatrix with top-left co-ordinate (i1,j1)
  188. -        -- copying is done by rows
  189. -    -- out is resized if necessary */
  190. -MAT    *vm_move(in,i0,out,i1,j1,m1,n1)
  191. -VEC    *in;
  192. -MAT    *out;
  193. -int    i0, i1, j1, m1, n1;
  194. -{
  195. -    int        dim0, i;
  196. -
  197. -    if ( ! in )
  198. -    error(E_NULL,"vm_move");
  199. -    if ( i0 < 0 || i1 < 0 || j1 < 0 || m1 < 0 || n1 < 0 ||
  200. -     i0+m1*n1 > in->dim )
  201. -    error(E_BOUNDS,"vm_move");
  202. -
  203. -    if ( ! out )
  204. -    out = m_resize(out,i1+m1,j1+n1);
  205. -    else
  206. -    out = m_resize(out,max(i1+m1,out->m),max(j1+n1,out->n));
  207. -
  208. -    dim0 = m1*n1;
  209. -    for ( i = 0; i < m1; i++ )
  210. -    MEM_COPY(&(in->ve[i0+i*n1]),&(out->me[i1+i][j1]),n1*sizeof(Real));
  211. -
  212. -    return out;
  213. -}
  214. //GO.SYSIN DD copy.c
  215. echo err.c 1>&2
  216. sed >err.c <<'//GO.SYSIN DD err.c' 's/^-//'
  217. -
  218. -/**************************************************************************
  219. -**
  220. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  221. -**
  222. -**                 Meschach Library
  223. -** 
  224. -** This Meschach Library is provided "as is" without any express 
  225. -** or implied warranty of any kind with respect to this software. 
  226. -** In particular the authors shall not be liable for any direct, 
  227. -** indirect, special, incidental or consequential damages arising 
  228. -** in any way from use of the software.
  229. -** 
  230. -** Everyone is granted permission to copy, modify and redistribute this
  231. -** Meschach Library, provided:
  232. -**  1.  All copies contain this copyright notice.
  233. -**  2.  All modified copies shall carry a notice stating who
  234. -**      made the last modification and the date of such modification.
  235. -**  3.  No charge is made for this software or works derived from it.  
  236. -**      This clause shall not be construed as constraining other software
  237. -**      distributed on the same medium as this software, nor is a
  238. -**      distribution fee considered a charge.
  239. -**
  240. -***************************************************************************/
  241. -
  242. -
  243. -/*
  244. -  File with basic error-handling operations
  245. -  Based on previous version on Zilog
  246. -  System 8000 setret() etc.
  247. -  Ported to Pyramid 9810 late 1987
  248. -  */
  249. -
  250. -static    char    rcsid[] = "$Id: err.c,v 1.5 1994/01/13 05:37:35 des Exp $";
  251. -
  252. -#include    <stdio.h>
  253. -#include    <setjmp.h>
  254. -#include    <ctype.h>
  255. -#include        "err.h"
  256. -
  257. -
  258. -#ifdef SYSV
  259. -/* AT&T System V */
  260. -#include    <sys/signal.h>
  261. -#else
  262. -/* something else -- assume BSD or ANSI C */
  263. -#include    <signal.h>
  264. -#endif
  265. -
  266. -
  267. -
  268. -#define        FALSE    0
  269. -#define        TRUE    1
  270. -
  271. -#define    EF_EXIT        0
  272. -#define    EF_ABORT    1
  273. -#define    EF_JUMP        2
  274. -#define    EF_SILENT    3
  275. -
  276. -/* The only error caught in this file! */
  277. -#define    E_SIGNAL    16
  278. -
  279. -static    char    *err_mesg[] =
  280. -{      "unknown error",            /* 0 */
  281. -      "sizes of objects don't match",    /* 1 */
  282. -      "index out of bounds",        /* 2 */
  283. -      "can't allocate memory",        /* 3 */
  284. -      "singular matrix",            /* 4 */
  285. -      "matrix not positive definite",    /* 5 */
  286. -      "incorrect format input",        /* 6 */
  287. -      "bad input file/device",        /* 7 */
  288. -      "NULL objects passed",        /* 8 */
  289. -      "matrix not square",            /* 9 */
  290. -      "object out of range",        /* 10 */
  291. -      "can't do operation in situ for non-square matrix",   /* 11 */
  292. -      "can't do operation in situ",        /* 12 */
  293. -      "excessive number of iterations",    /* 13 */
  294. -      "convergence criterion failed",    /* 14 */
  295. -      "bad starting value",            /* 15 */
  296. -      "floating exception",            /* 16 */
  297. -      "internal inconsistency (data structure)",/* 17 */
  298. -      "unexpected end-of-file",        /* 18 */
  299. -      "shared vectors (cannot release them)",  /* 19 */  
  300. -      "negative argument",            /* 20 */
  301. -      "cannot overwrite object"             /* 21 */
  302. -     };
  303. -
  304. -#define    MAXERR    (sizeof(err_mesg)/sizeof(char *))
  305. -
  306. -static char *warn_mesg[] = {
  307. -   "unknown warning",                /* 0 */
  308. -   "wrong type number (use macro TYPE_*)",    /* 1 */
  309. -   "no corresponding mem_stat_mark",        /* 2 */
  310. -   "computed norm of a residual is less than 0",  /* 3 */
  311. -   "resizing a shared vector"            /* 4 */
  312. -};
  313. -
  314. -#define MAXWARN  (sizeof(warn_mesg)/sizeof(char *))
  315. -
  316. -
  317. -
  318. -#define    MAX_ERRS    100
  319. -
  320. -jmp_buf    restart;
  321. -
  322. -
  323. -/* array of pointers to lists of errors */
  324. -
  325. -typedef struct {
  326. -   char **listp;    /* pointer to a list of errors */
  327. -   unsigned len;    /* length of the list */
  328. -   unsigned warn;   /* =FALSE - errors, =TRUE - warnings */
  329. -}  Err_list;
  330. -
  331. -static Err_list     err_list[ERR_LIST_MAX_LEN] = {
  332. - {err_mesg,MAXERR,FALSE},    /* basic errors list */
  333. - {warn_mesg,MAXWARN,TRUE}    /* basic warnings list */
  334. -};
  335. -
  336. -
  337. -static int err_list_end = 2;   /* number of elements in err_list */
  338. -
  339. -/* attach a new list of errors pointed by err_ptr
  340. -   or change a previous one;
  341. -   list_len is the number of elements in the list;
  342. -   list_num is the list number;
  343. -   warn == FALSE - errors (stop the program),
  344. -   warn == TRUE - warnings (continue the program);
  345. -   Note: lists numbered 0 and 1 are attached automatically,
  346. -   you do not need to do it
  347. -   */
  348. -int err_list_attach(list_num, list_len,err_ptr,warn)
  349. -int list_num, list_len, warn;
  350. -char **err_ptr;
  351. -{
  352. -   if (list_num < 0 || list_len <= 0 ||
  353. -       err_ptr == (char **)NULL) 
  354. -     return -1;
  355. -   
  356. -   if (list_num >= ERR_LIST_MAX_LEN) {
  357. -    fprintf(stderr,"\n file \"%s\": %s %s\n",
  358. -        "err.c","increase the value of ERR_LIST_MAX_LEN",
  359. -        "in matrix.h and zmatdef.h");
  360. -    if ( ! isatty(fileno(stdout)) )
  361. -      fprintf(stderr,"\n file \"%s\": %s %s\n",
  362. -          "err.c","increase the value of ERR_LIST_MAX_LEN",
  363. -          "in matrix.h and zmatdef.h");
  364. -    printf("Exiting program\n");
  365. -    exit(0);
  366. -     }
  367. -
  368. -   if (err_list[list_num].listp != (char **)NULL &&
  369. -       err_list[list_num].listp != err_ptr)
  370. -     free((char *)err_list[list_num].listp);
  371. -   err_list[list_num].listp = err_ptr;
  372. -   err_list[list_num].len = list_len;
  373. -   err_list[list_num].warn = warn;
  374. -   err_list_end = list_num+1;
  375. -   
  376. -   return list_num;
  377. -}
  378. -
  379. -
  380. -/* release the error list numbered list_num */
  381. -int err_list_free(list_num)
  382. -int list_num;
  383. -{
  384. -   if (list_num < 0 || list_num >= err_list_end) return -1;
  385. -   if (err_list[list_num].listp != (char **)NULL) {
  386. -      err_list[list_num].listp = (char **)NULL;
  387. -      err_list[list_num].len = 0;
  388. -      err_list[list_num].warn = 0;
  389. -   }
  390. -   return 0;
  391. -}
  392. -
  393. -
  394. -/* check if list_num is attached;
  395. -   return FALSE if not;
  396. -   return TRUE if yes
  397. -   */
  398. -int err_is_list_attached(list_num)
  399. -int list_num;
  400. -{
  401. -   if (list_num < 0 || list_num >= err_list_end)
  402. -     return FALSE;
  403. -   
  404. -   if (err_list[list_num].listp != (char **)NULL)
  405. -     return TRUE;
  406. -   
  407. -   return FALSE;
  408. -}
  409. -
  410. -/* other local variables */
  411. -
  412. -static    int    err_flag = EF_EXIT, num_errs = 0, cnt_errs = 1;
  413. -
  414. -/* set_err_flag -- sets err_flag -- returns old err_flag */
  415. -int    set_err_flag(flag)
  416. -int    flag;
  417. -{
  418. -   int    tmp;
  419. -   
  420. -   tmp = err_flag;
  421. -   err_flag = flag;
  422. -   return tmp;
  423. -}
  424. -
  425. -/* count_errs -- sets cnt_errs (TRUE/FALSE) & returns old value */
  426. -int    count_errs(flag)
  427. -int    flag;
  428. -{
  429. -   int    tmp;
  430. -   
  431. -   tmp = cnt_errs;
  432. -   cnt_errs = flag;
  433. -   return tmp;
  434. -}
  435. -
  436. -/* ev_err -- reports error (err_num) in file "file" at line "line_num" and
  437. -   returns to user error handler;
  438. -   list_num is an error list number (0 is the basic list 
  439. -   pointed by err_mesg, 1 is the basic list of warnings)
  440. - */
  441. -int    ev_err(file,err_num,line_num,fn_name,list_num)
  442. -char    *file, *fn_name;
  443. -int    err_num, line_num,list_num;
  444. -{
  445. -   int    num;
  446. -   
  447. -   if ( err_num < 0 ) err_num = 0;
  448. -   
  449. -   if (list_num < 0 || list_num >= err_list_end ||
  450. -       err_list[list_num].listp == (char **)NULL) {
  451. -      fprintf(stderr,
  452. -          "\n Not (properly) attached list of errors: list_num = %d\n",
  453. -          list_num);
  454. -      fprintf(stderr," Call \"err_list_attach\" in your program\n");
  455. -      if ( ! isatty(fileno(stdout)) ) {
  456. -     fprintf(stderr,
  457. -         "\n Not (properly) attached list of errors: list_num = %d\n",
  458. -         list_num);
  459. -     fprintf(stderr," Call \"err_list_attach\" in your program\n");
  460. -      }
  461. -      printf("\nExiting program\n");
  462. -      exit(0);
  463. -   }
  464. -   
  465. -   num = err_num;
  466. -   if ( num >= err_list[list_num].len ) num = 0;
  467. -   
  468. -   if ( cnt_errs && ++num_errs >= MAX_ERRS )    /* too many errors */
  469. -   {
  470. -      fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n",
  471. -          file,line_num,err_list[list_num].listp[num],
  472. -          isascii(*fn_name) ? fn_name : "???");
  473. -      if ( ! isatty(fileno(stdout)) )
  474. -    fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n",
  475. -        file,line_num,err_list[list_num].listp[num],
  476. -        isascii(*fn_name) ? fn_name : "???");
  477. -      printf("Sorry, too many errors: %d\n",num_errs);
  478. -      printf("Exiting program\n");
  479. -      exit(0);
  480. -   }
  481. -   if ( err_list[list_num].warn )
  482. -       switch ( err_flag )
  483. -       {
  484. -       case EF_SILENT: break;
  485. -       default:
  486. -       fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n\n",
  487. -           file,line_num,err_list[list_num].listp[num],
  488. -           isascii(*fn_name) ? fn_name : "???");
  489. -       if ( ! isatty(fileno(stdout)) )
  490. -           fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n\n",
  491. -               file,line_num,err_list[list_num].listp[num],
  492. -               isascii(*fn_name) ? fn_name : "???");
  493. -       break;
  494. -       }
  495. -   else
  496. -       switch ( err_flag )
  497. -       {
  498. -       case EF_SILENT:
  499. -       longjmp(restart,(err_num==0)? -1 : err_num);
  500. -       break;
  501. -       case EF_ABORT:
  502. -       fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n",
  503. -           file,line_num,err_list[list_num].listp[num],
  504. -           isascii(*fn_name) ? fn_name : "???");
  505. -       if ( ! isatty(fileno(stdout)) )
  506. -           fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n",
  507. -               file,line_num,err_list[list_num].listp[num],
  508. -               isascii(*fn_name) ? fn_name : "???");
  509. -       abort();
  510. -       break;
  511. -       case EF_JUMP:
  512. -       fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n",
  513. -           file,line_num,err_list[list_num].listp[num],
  514. -           isascii(*fn_name) ? fn_name : "???");
  515. -       if ( ! isatty(fileno(stdout)) )
  516. -           fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n",
  517. -               file,line_num,err_list[list_num].listp[num],
  518. -               isascii(*fn_name) ? fn_name : "???");
  519. -       longjmp(restart,(err_num==0)? -1 : err_num);
  520. -       break;
  521. -       default:
  522. -       fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n\n",
  523. -           file,line_num,err_list[list_num].listp[num],
  524. -           isascii(*fn_name) ? fn_name : "???");
  525. -       if ( ! isatty(fileno(stdout)) )
  526. -           fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n\n",
  527. -               file,line_num,err_list[list_num].listp[num],
  528. -               isascii(*fn_name) ? fn_name : "???");
  529. -       
  530. -       break;
  531. -       }
  532. -   
  533. -   /* ensure exit if fall through */
  534. -   if ( ! err_list[list_num].warn )  exit(0);
  535. -
  536. -   return 0;
  537. -}
  538. -
  539. -/* float_error -- catches floating arithmetic signals */
  540. -static void    float_error(num)
  541. -int    num;
  542. -{
  543. -   signal(SIGFPE,float_error);
  544. -   /* fprintf(stderr,"SIGFPE: signal #%d\n",num); */
  545. -   /* fprintf(stderr,"errno = %d\n",errno); */
  546. -   ev_err("???.c",E_SIGNAL,0,"???",0);
  547. -}
  548. -
  549. -/* catch_signal -- sets up float_error() to catch SIGFPE's */
  550. -void    catch_FPE()
  551. -{
  552. -   signal(SIGFPE,float_error);
  553. -}
  554. -
  555. //GO.SYSIN DD err.c
  556. echo matrixio.c 1>&2
  557. sed >matrixio.c <<'//GO.SYSIN DD matrixio.c' 's/^-//'
  558. -
  559. -/**************************************************************************
  560. -**
  561. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  562. -**
  563. -**                 Meschach Library
  564. -** 
  565. -** This Meschach Library is provided "as is" without any express 
  566. -** or implied warranty of any kind with respect to this software. 
  567. -** In particular the authors shall not be liable for any direct, 
  568. -** indirect, special, incidental or consequential damages arising 
  569. -** in any way from use of the software.
  570. -** 
  571. -** Everyone is granted permission to copy, modify and redistribute this
  572. -** Meschach Library, provided:
  573. -**  1.  All copies contain this copyright notice.
  574. -**  2.  All modified copies shall carry a notice stating who
  575. -**      made the last modification and the date of such modification.
  576. -**  3.  No charge is made for this software or works derived from it.  
  577. -**      This clause shall not be construed as constraining other software
  578. -**      distributed on the same medium as this software, nor is a
  579. -**      distribution fee considered a charge.
  580. -**
  581. -***************************************************************************/
  582. -
  583. -
  584. -/* 1.6 matrixio.c 11/25/87 */
  585. -
  586. -
  587. -#include        <stdio.h>
  588. -#include        <ctype.h>
  589. -#include        "matrix.h"
  590. -
  591. -static char rcsid[] = "$Id: matrixio.c,v 1.4 1994/01/13 05:31:10 des Exp $";
  592. -
  593. -
  594. -/* local variables */
  595. -static char line[MAXLINE];
  596. -
  597. -
  598. -/**************************************************************************
  599. -  Input routines
  600. -  **************************************************************************/
  601. -/* skipjunk -- skips white spaces and strings of the form #....\n
  602. -   Here .... is a comment string */
  603. -int     skipjunk(fp)
  604. -FILE    *fp;
  605. -{
  606. -     int        c;
  607. -     
  608. -     for ( ; ; )        /* forever do... */
  609. -     {
  610. -      /* skip blanks */
  611. -      do
  612. -           c = getc(fp);
  613. -      while ( isspace(c) );
  614. -      
  615. -      /* skip comments (if any) */
  616. -      if ( c == '#' )
  617. -           /* yes it is a comment (line) */
  618. -           while ( (c=getc(fp)) != '\n' )
  619. -            ;
  620. -      else
  621. -      {
  622. -           ungetc(c,fp);
  623. -           break;
  624. -      }
  625. -     }
  626. -     return 0;
  627. -}
  628. -
  629. -MAT     *m_finput(fp,a)
  630. -FILE    *fp;
  631. -MAT     *a;
  632. -{
  633. -     MAT        *im_finput(),*bm_finput();
  634. -     
  635. -     if ( isatty(fileno(fp)) )
  636. -      return im_finput(fp,a);
  637. -     else
  638. -      return bm_finput(fp,a);
  639. -}
  640. -
  641. -/* im_finput -- interactive input of matrix */
  642. -MAT     *im_finput(fp,mat)
  643. -FILE    *fp;
  644. -MAT     *mat;
  645. -{
  646. -     char       c;
  647. -     u_int      i, j, m, n, dynamic;
  648. -     /* dynamic set to TRUE if memory allocated here */
  649. -     
  650. -     /* get matrix size */
  651. -     if ( mat != (MAT *)NULL && mat->m<MAXDIM && mat->n<MAXDIM )
  652. -     {  m = mat->m;     n = mat->n;     dynamic = FALSE;        }
  653. -     else
  654. -     {
  655. -      dynamic = TRUE;
  656. -      do
  657. -      {
  658. -           fprintf(stderr,"Matrix: rows cols:");
  659. -           if ( fgets(line,MAXLINE,fp)==NULL )
  660. -            error(E_INPUT,"im_finput");
  661. -      } while ( sscanf(line,"%u%u",&m,&n)<2 || m>MAXDIM || n>MAXDIM );
  662. -      mat = m_get(m,n);
  663. -     }
  664. -     
  665. -     /* input elements */
  666. -     for ( i=0; i<m; i++ )
  667. -     {
  668. -     redo:
  669. -      fprintf(stderr,"row %u:\n",i);
  670. -      for ( j=0; j<n; j++ )
  671. -           do
  672. -           {
  673. -           redo2:
  674. -            fprintf(stderr,"entry (%u,%u): ",i,j);
  675. -            if ( !dynamic )
  676. -             fprintf(stderr,"old %14.9g new: ",
  677. -                 mat->me[i][j]);
  678. -            if ( fgets(line,MAXLINE,fp)==NULL )
  679. -             error(E_INPUT,"im_finput");
  680. -            if ( (*line == 'b' || *line == 'B') && j > 0 )
  681. -            {   j--;    dynamic = FALSE;        goto redo2;     }
  682. -            if ( (*line == 'f' || *line == 'F') && j < n-1 )
  683. -            {   j++;    dynamic = FALSE;        goto redo2;     }
  684. -#if REAL == DOUBLE
  685. -           } while ( *line=='\0' || sscanf(line,"%lf",&mat->me[i][j])<1 );
  686. -#elif REAL == FLOAT
  687. -           } while ( *line=='\0' || sscanf(line,"%f",&mat->me[i][j])<1 );
  688. -#endif
  689. -      fprintf(stderr,"Continue: ");
  690. -      fscanf(fp,"%c",&c);
  691. -      if ( c == 'n' || c == 'N' )
  692. -      {    dynamic = FALSE;                 goto redo;      }
  693. -      if ( (c == 'b' || c == 'B') /* && i > 0 */ )
  694. -      {     if ( i > 0 )
  695. -            i--;
  696. -        dynamic = FALSE;        goto redo;
  697. -      }
  698. -     }
  699. -     
  700. -     return (mat);
  701. -}
  702. -
  703. -/* bm_finput -- batch-file input of matrix */
  704. -MAT     *bm_finput(fp,mat)
  705. -FILE    *fp;
  706. -MAT     *mat;
  707. -{
  708. -     u_int      i,j,m,n,dummy;
  709. -     int        io_code;
  710. -     
  711. -     /* get dimension */
  712. -     skipjunk(fp);
  713. -     if ((io_code=fscanf(fp," Matrix: %u by %u",&m,&n)) < 2 ||
  714. -     m>MAXDIM || n>MAXDIM )
  715. -      error(io_code==EOF ? E_EOF : E_FORMAT,"bm_finput");
  716. -     
  717. -     /* allocate memory if necessary */
  718. -     if ( mat==(MAT *)NULL )
  719. -      mat = m_resize(mat,m,n);
  720. -     
  721. -     /* get entries */
  722. -     for ( i=0; i<m; i++ )
  723. -     {
  724. -      skipjunk(fp);
  725. -      if ( fscanf(fp," row %u:",&dummy) < 1 )
  726. -           error(E_FORMAT,"bm_finput");
  727. -      for ( j=0; j<n; j++ )
  728. -#if REAL == DOUBLE
  729. -           if ((io_code=fscanf(fp,"%lf",&mat->me[i][j])) < 1 )
  730. -#elif REAL == FLOAT
  731. -           if ((io_code=fscanf(fp,"%f",&mat->me[i][j])) < 1 )
  732. -#endif
  733. -            error(io_code==EOF ? 7 : 6,"bm_finput");
  734. -     }
  735. -     
  736. -     return (mat);
  737. -}
  738. -
  739. -PERM    *px_finput(fp,px)
  740. -FILE    *fp;
  741. -PERM    *px;
  742. -{
  743. -     PERM       *ipx_finput(),*bpx_finput();
  744. -     
  745. -     if ( isatty(fileno(fp)) )
  746. -      return ipx_finput(fp,px);
  747. -     else
  748. -      return bpx_finput(fp,px);
  749. -}
  750. -
  751. -
  752. -/* ipx_finput -- interactive input of permutation */
  753. -PERM    *ipx_finput(fp,px)
  754. -FILE    *fp;
  755. -PERM    *px;
  756. -{
  757. -     u_int      i,j,size,dynamic; /* dynamic set if memory allocated here */
  758. -     u_int      entry,ok;
  759. -     
  760. -     /* get permutation size */
  761. -     if ( px!=(PERM *)NULL && px->size<MAXDIM )
  762. -     {  size = px->size;        dynamic = FALSE;        }
  763. -     else
  764. -     {
  765. -      dynamic = TRUE;
  766. -      do
  767. -      {
  768. -           fprintf(stderr,"Permutation: size: ");
  769. -           if ( fgets(line,MAXLINE,fp)==NULL )
  770. -            error(E_INPUT,"ipx_finput");
  771. -      } while ( sscanf(line,"%u",&size)<1 || size>MAXDIM );
  772. -      px = px_get(size);
  773. -     }
  774. -     
  775. -     /* get entries */
  776. -     i = 0;
  777. -     while ( i<size )
  778. -     {
  779. -      /* input entry */
  780. -      do
  781. -      {
  782. -      redo:
  783. -           fprintf(stderr,"entry %u: ",i);
  784. -           if ( !dynamic )
  785. -            fprintf(stderr,"old: %u->%u new: ",
  786. -                i,px->pe[i]);
  787. -           if ( fgets(line,MAXLINE,fp)==NULL )
  788. -            error(E_INPUT,"ipx_finput");
  789. -           if ( (*line == 'b' || *line == 'B') && i > 0 )
  790. -           {        i--;    dynamic = FALSE;        goto redo;      }
  791. -      } while ( *line=='\0' || sscanf(line,"%u",&entry) < 1 );
  792. -      /* check entry */
  793. -      ok = (entry < size);
  794. -      for ( j=0; j<i; j++ )
  795. -           ok &= (entry != px->pe[j]);
  796. -      if ( ok )
  797. -      {
  798. -           px->pe[i] = entry;
  799. -           i++;
  800. -      }
  801. -     }
  802. -     
  803. -     return (px);
  804. -}
  805. -
  806. -/* bpx_finput -- batch-file input of permutation */
  807. -PERM    *bpx_finput(fp,px)
  808. -FILE    *fp;
  809. -PERM    *px;
  810. -{
  811. -     u_int      i,j,size,entry,ok;
  812. -     int        io_code;
  813. -     
  814. -     /* get size of permutation */
  815. -     skipjunk(fp);
  816. -     if ((io_code=fscanf(fp," Permutation: size:%u",&size)) < 1 ||
  817. -     size>MAXDIM )
  818. -      error(io_code==EOF ? 7 : 6,"bpx_finput");
  819. -     
  820. -     /* allocate memory if necessary */
  821. -     if ( px==(PERM *)NULL || px->size<size )
  822. -      px = px_resize(px,size);
  823. -     
  824. -     /* get entries */
  825. -     skipjunk(fp);
  826. -     i = 0;
  827. -     while ( i<size )
  828. -     {
  829. -      /* input entry */
  830. -      if ((io_code=fscanf(fp,"%*u -> %u",&entry)) < 1 )
  831. -           error(io_code==EOF ? 7 : 6,"bpx_finput");
  832. -      /* check entry */
  833. -      ok = (entry < size);
  834. -      for ( j=0; j<i; j++ )
  835. -           ok &= (entry != px->pe[j]);
  836. -      if ( ok )
  837. -      {
  838. -           px->pe[i] = entry;
  839. -           i++;
  840. -      }
  841. -      else
  842. -           error(E_BOUNDS,"bpx_finput");
  843. -     }
  844. -     
  845. -     return (px);
  846. -}
  847. -
  848. -
  849. -VEC     *v_finput(fp,x)
  850. -FILE    *fp;
  851. -VEC     *x;
  852. -{
  853. -     VEC        *ifin_vec(),*bfin_vec();
  854. -     
  855. -     if ( isatty(fileno(fp)) )
  856. -      return ifin_vec(fp,x);
  857. -     else
  858. -      return bfin_vec(fp,x);
  859. -}
  860. -
  861. -/* ifin_vec -- interactive input of vector */
  862. -VEC     *ifin_vec(fp,vec)
  863. -FILE    *fp;
  864. -VEC     *vec;
  865. -{
  866. -     u_int      i,dim,dynamic;  /* dynamic set if memory allocated here */
  867. -     
  868. -     /* get vector dimension */
  869. -     if ( vec != (VEC *)NULL && vec->dim<MAXDIM )
  870. -     {  dim = vec->dim; dynamic = FALSE;        }
  871. -     else
  872. -     {
  873. -      dynamic = TRUE;
  874. -      do
  875. -      {
  876. -           fprintf(stderr,"Vector: dim: ");
  877. -           if ( fgets(line,MAXLINE,fp)==NULL )
  878. -            error(E_INPUT,"ifin_vec");
  879. -      } while ( sscanf(line,"%u",&dim)<1 || dim>MAXDIM );
  880. -      vec = v_get(dim);
  881. -     }
  882. -     
  883. -     /* input elements */
  884. -     for ( i=0; i<dim; i++ )
  885. -      do
  886. -      {
  887. -      redo:
  888. -           fprintf(stderr,"entry %u: ",i);
  889. -           if ( !dynamic )
  890. -            fprintf(stderr,"old %14.9g new: ",vec->ve[i]);
  891. -           if ( fgets(line,MAXLINE,fp)==NULL )
  892. -            error(E_INPUT,"ifin_vec");
  893. -           if ( (*line == 'b' || *line == 'B') && i > 0 )
  894. -           {        i--;    dynamic = FALSE;        goto redo;         }
  895. -           if ( (*line == 'f' || *line == 'F') && i < dim-1 )
  896. -           {        i++;    dynamic = FALSE;        goto redo;         }
  897. -#if REAL == DOUBLE
  898. -      } while ( *line=='\0' || sscanf(line,"%lf",&vec->ve[i]) < 1 );
  899. -#elif REAL == FLOAT
  900. -          } while ( *line=='\0' || sscanf(line,"%f",&vec->ve[i]) < 1 );
  901. -#endif
  902. -     
  903. -     return (vec);
  904. -}
  905. -
  906. -/* bfin_vec -- batch-file input of vector */
  907. -VEC     *bfin_vec(fp,vec)
  908. -FILE    *fp;
  909. -VEC     *vec;
  910. -{
  911. -     u_int      i,dim;
  912. -     int        io_code;
  913. -     
  914. -     /* get dimension */
  915. -     skipjunk(fp);
  916. -     if ((io_code=fscanf(fp," Vector: dim:%u",&dim)) < 1 ||
  917. -     dim>MAXDIM )
  918. -      error(io_code==EOF ? 7 : 6,"bfin_vec");
  919. -     
  920. -     /* allocate memory if necessary */
  921. -     if ( vec==(VEC *)NULL )
  922. -      vec = v_resize(vec,dim);
  923. -     
  924. -     /* get entries */
  925. -     skipjunk(fp);
  926. -     for ( i=0; i<dim; i++ )
  927. -#if REAL == DOUBLE
  928. -      if ((io_code=fscanf(fp,"%lf",&vec->ve[i])) < 1 )
  929. -#elif REAL == FLOAT
  930. -      if ((io_code=fscanf(fp,"%f",&vec->ve[i])) < 1 )
  931. -#endif
  932. -           error(io_code==EOF ? 7 : 6,"bfin_vec");
  933. -     
  934. -     return (vec);
  935. -}
  936. -
  937. -/**************************************************************************
  938. -  Output routines
  939. -  **************************************************************************/
  940. -static char    *format = "%14.9g ";
  941. -
  942. -char    *setformat(f_string)
  943. -char    *f_string;
  944. -{
  945. -    char    *old_f_string;
  946. -    old_f_string = format;
  947. -    if ( f_string != (char *)NULL && *f_string != '\0' )
  948. -    format = f_string;
  949. -
  950. -    return old_f_string;
  951. -}
  952. -
  953. -void    m_foutput(fp,a)
  954. -FILE    *fp;
  955. -MAT     *a;
  956. -{
  957. -     u_int      i, j, tmp;
  958. -     
  959. -     if ( a == (MAT *)NULL )
  960. -     {  fprintf(fp,"Matrix: NULL\n");   return;         }
  961. -     fprintf(fp,"Matrix: %d by %d\n",a->m,a->n);
  962. -     if ( a->me == (Real **)NULL )
  963. -     {  fprintf(fp,"NULL\n");           return;         }
  964. -     for ( i=0; i<a->m; i++ )   /* for each row... */
  965. -     {
  966. -      fprintf(fp,"row %u: ",i);
  967. -      for ( j=0, tmp=2; j<a->n; j++, tmp++ )
  968. -      {             /* for each col in row... */
  969. -           fprintf(fp,format,a->me[i][j]);
  970. -           if ( ! (tmp % 5) )       putc('\n',fp);
  971. -      }
  972. -      if ( tmp % 5 != 1 )   putc('\n',fp);
  973. -     }
  974. -}
  975. -
  976. -void    px_foutput(fp,px)
  977. -FILE    *fp;
  978. -PERM    *px;
  979. -{
  980. -     u_int      i;
  981. -     
  982. -     if ( px == (PERM *)NULL )
  983. -     {  fprintf(fp,"Permutation: NULL\n");      return;         }
  984. -     fprintf(fp,"Permutation: size: %u\n",px->size);
  985. -     if ( px->pe == (u_int *)NULL )
  986. -     {  fprintf(fp,"NULL\n");   return;         }
  987. -     for ( i=0; i<px->size; i++ )
  988. -    if ( ! (i % 8) && i != 0 )
  989. -      fprintf(fp,"\n  %u->%u ",i,px->pe[i]);
  990. -    else
  991. -      fprintf(fp,"%u->%u ",i,px->pe[i]);
  992. -     fprintf(fp,"\n");
  993. -}
  994. -
  995. -void    v_foutput(fp,x)
  996. -FILE    *fp;
  997. -VEC     *x;
  998. -{
  999. -     u_int      i, tmp;
  1000. -     
  1001. -     if ( x == (VEC *)NULL )
  1002. -     {  fprintf(fp,"Vector: NULL\n");   return;         }
  1003. -     fprintf(fp,"Vector: dim: %d\n",x->dim);
  1004. -     if ( x->ve == (Real *)NULL )
  1005. -     {  fprintf(fp,"NULL\n");   return;         }
  1006. -     for ( i=0, tmp=0; i<x->dim; i++, tmp++ )
  1007. -     {
  1008. -      fprintf(fp,format,x->ve[i]);
  1009. -      if ( tmp % 5 == 4 )   putc('\n',fp);
  1010. -     }
  1011. -     if ( tmp % 5 != 0 )        putc('\n',fp);
  1012. -}
  1013. -
  1014. -
  1015. -void    m_dump(fp,a)
  1016. -FILE    *fp;
  1017. -MAT     *a;
  1018. -{
  1019. -    u_int   i, j, tmp;
  1020. -     
  1021. -     if ( a == (MAT *)NULL )
  1022. -     {  fprintf(fp,"Matrix: NULL\n");   return;         }
  1023. -     fprintf(fp,"Matrix: %d by %d @ 0x%lx\n",a->m,a->n,(long)a);
  1024. -     fprintf(fp,"\tmax_m = %d, max_n = %d, max_size = %d\n",
  1025. -         a->max_m, a->max_n, a->max_size);
  1026. -     if ( a->me == (Real **)NULL )
  1027. -     {  fprintf(fp,"NULL\n");           return;         }
  1028. -     fprintf(fp,"a->me @ 0x%lx\n",(long)(a->me));
  1029. -     fprintf(fp,"a->base @ 0x%lx\n",(long)(a->base));
  1030. -     for ( i=0; i<a->m; i++ )   /* for each row... */
  1031. -     {
  1032. -      fprintf(fp,"row %u: @ 0x%lx ",i,(long)(a->me[i]));
  1033. -      for ( j=0, tmp=2; j<a->n; j++, tmp++ )
  1034. -      {             /* for each col in row... */
  1035. -           fprintf(fp,format,a->me[i][j]);
  1036. -           if ( ! (tmp % 5) )       putc('\n',fp);
  1037. -      }
  1038. -      if ( tmp % 5 != 1 )   putc('\n',fp);
  1039. -     }
  1040. -}
  1041. -
  1042. -void    px_dump(fp,px)
  1043. -FILE    *fp;
  1044. -PERM    *px;
  1045. -{
  1046. -     u_int      i;
  1047. -     
  1048. -     if ( ! px )
  1049. -     {  fprintf(fp,"Permutation: NULL\n");      return;         }
  1050. -     fprintf(fp,"Permutation: size: %u @ 0x%lx\n",px->size,(long)(px));
  1051. -     if ( ! px->pe )
  1052. -     {  fprintf(fp,"NULL\n");   return;         }
  1053. -     fprintf(fp,"px->pe @ 0x%lx\n",(long)(px->pe));
  1054. -     for ( i=0; i<px->size; i++ )
  1055. -      fprintf(fp,"%u->%u ",i,px->pe[i]);
  1056. -     fprintf(fp,"\n");
  1057. -}
  1058. -
  1059. -
  1060. -void    v_dump(fp,x)
  1061. -FILE    *fp;
  1062. -VEC     *x;
  1063. -{
  1064. -     u_int      i, tmp;
  1065. -     
  1066. -     if ( ! x )
  1067. -     {  fprintf(fp,"Vector: NULL\n");   return;         }
  1068. -     fprintf(fp,"Vector: dim: %d @ 0x%lx\n",x->dim,(long)(x));
  1069. -     if ( ! x->ve )
  1070. -     {  fprintf(fp,"NULL\n");   return;         }
  1071. -     fprintf(fp,"x->ve @ 0x%lx\n",(long)(x->ve));
  1072. -     for ( i=0, tmp=0; i<x->dim; i++, tmp++ )
  1073. -     {
  1074. -      fprintf(fp,format,x->ve[i]);
  1075. -      if ( tmp % 5 == 4 )   putc('\n',fp);
  1076. -     }
  1077. -     if ( tmp % 5 != 0 )        putc('\n',fp);
  1078. -}
  1079. -
  1080. //GO.SYSIN DD matrixio.c
  1081. echo memory.c 1>&2
  1082. sed >memory.c <<'//GO.SYSIN DD memory.c' 's/^-//'
  1083. -
  1084. -/**************************************************************************
  1085. -**
  1086. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  1087. -**
  1088. -**                 Meschach Library
  1089. -** 
  1090. -** This Meschach Library is provided "as is" without any express 
  1091. -** or implied warranty of any kind with respect to this software. 
  1092. -** In particular the authors shall not be liable for any direct, 
  1093. -** indirect, special, incidental or consequential damages arising 
  1094. -** in any way from use of the software.
  1095. -** 
  1096. -** Everyone is granted permission to copy, modify and redistribute this
  1097. -** Meschach Library, provided:
  1098. -**  1.  All copies contain this copyright notice.
  1099. -**  2.  All modified copies shall carry a notice stating who
  1100. -**      made the last modification and the date of such modification.
  1101. -**  3.  No charge is made for this software or works derived from it.  
  1102. -**      This clause shall not be construed as constraining other software
  1103. -**      distributed on the same medium as this software, nor is a
  1104. -**      distribution fee considered a charge.
  1105. -**
  1106. -***************************************************************************/
  1107. -
  1108. -
  1109. -/* memory.c 1.3 11/25/87 */
  1110. -
  1111. -#include     "matrix.h"
  1112. -
  1113. -
  1114. -static    char    rcsid[] = "$Id: memory.c,v 1.13 1994/04/05 02:10:37 des Exp $";
  1115. -
  1116. -/* m_get -- gets an mxn matrix (in MAT form) by dynamic memory allocation */
  1117. -MAT    *m_get(m,n)
  1118. -int    m,n;
  1119. -{
  1120. -   MAT    *matrix;
  1121. -   int    i;
  1122. -   
  1123. -   if (m < 0 || n < 0)
  1124. -     error(E_NEG,"m_get");
  1125. -
  1126. -   if ((matrix=NEW(MAT)) == (MAT *)NULL )
  1127. -     error(E_MEM,"m_get");
  1128. -   else if (mem_info_is_on()) {
  1129. -      mem_bytes(TYPE_MAT,0,sizeof(MAT));
  1130. -      mem_numvar(TYPE_MAT,1);
  1131. -   }
  1132. -   
  1133. -   matrix->m = m;        matrix->n = matrix->max_n = n;
  1134. -   matrix->max_m = m;    matrix->max_size = m*n;
  1135. -#ifndef SEGMENTED
  1136. -   if ((matrix->base = NEW_A(m*n,Real)) == (Real *)NULL )
  1137. -   {
  1138. -      free(matrix);
  1139. -      error(E_MEM,"m_get");
  1140. -   }
  1141. -   else if (mem_info_is_on()) {
  1142. -      mem_bytes(TYPE_MAT,0,m*n*sizeof(Real));
  1143. -   }
  1144. -#else
  1145. -   matrix->base = (Real *)NULL;
  1146. -#endif
  1147. -   if ((matrix->me = (Real **)calloc(m,sizeof(Real *))) == 
  1148. -       (Real **)NULL )
  1149. -   {    free(matrix->base);    free(matrix);
  1150. -    error(E_MEM,"m_get");
  1151. -     }
  1152. -   else if (mem_info_is_on()) {
  1153. -      mem_bytes(TYPE_MAT,0,m*sizeof(Real *));
  1154. -   }
  1155. -   
  1156. -#ifndef SEGMENTED
  1157. -   /* set up pointers */
  1158. -   for ( i=0; i<m; i++ )
  1159. -     matrix->me[i] = &(matrix->base[i*n]);
  1160. -#else
  1161. -   for ( i = 0; i < m; i++ )
  1162. -     if ( (matrix->me[i]=NEW_A(n,Real)) == (Real *)NULL )
  1163. -       error(E_MEM,"m_get");
  1164. -     else if (mem_info_is_on()) {
  1165. -    mem_bytes(TYPE_MAT,0,n*sizeof(Real));
  1166. -       }
  1167. -#endif
  1168. -   
  1169. -   return (matrix);
  1170. -}
  1171. -
  1172. -
  1173. -/* px_get -- gets a PERM of given 'size' by dynamic memory allocation
  1174. -   -- Note: initialized to the identity permutation */
  1175. -PERM    *px_get(size)
  1176. -int    size;
  1177. -{
  1178. -   PERM    *permute;
  1179. -   int    i;
  1180. -
  1181. -   if (size < 0)
  1182. -     error(E_NEG,"px_get");
  1183. -
  1184. -   if ((permute=NEW(PERM)) == (PERM *)NULL )
  1185. -     error(E_MEM,"px_get");
  1186. -   else if (mem_info_is_on()) {
  1187. -      mem_bytes(TYPE_PERM,0,sizeof(PERM));
  1188. -      mem_numvar(TYPE_PERM,1);
  1189. -   }
  1190. -   
  1191. -   permute->size = permute->max_size = size;
  1192. -   if ((permute->pe = NEW_A(size,u_int)) == (u_int *)NULL )
  1193. -     error(E_MEM,"px_get");
  1194. -   else if (mem_info_is_on()) {
  1195. -      mem_bytes(TYPE_PERM,0,size*sizeof(u_int));
  1196. -   }
  1197. -   
  1198. -   for ( i=0; i<size; i++ )
  1199. -     permute->pe[i] = i;
  1200. -   
  1201. -   return (permute);
  1202. -}
  1203. -
  1204. -/* v_get -- gets a VEC of dimension 'dim'
  1205. -   -- Note: initialized to zero */
  1206. -VEC    *v_get(size)
  1207. -int    size;
  1208. -{
  1209. -   VEC    *vector;
  1210. -   
  1211. -   if (size < 0)
  1212. -     error(E_NEG,"v_get");
  1213. -
  1214. -   if ((vector=NEW(VEC)) == (VEC *)NULL )
  1215. -     error(E_MEM,"v_get");
  1216. -   else if (mem_info_is_on()) {
  1217. -      mem_bytes(TYPE_VEC,0,sizeof(VEC));
  1218. -      mem_numvar(TYPE_VEC,1);
  1219. -   }
  1220. -   
  1221. -   vector->dim = vector->max_dim = size;
  1222. -   if ((vector->ve=NEW_A(size,Real)) == (Real *)NULL )
  1223. -   {
  1224. -      free(vector);
  1225. -      error(E_MEM,"v_get");
  1226. -   }
  1227. -   else if (mem_info_is_on()) {
  1228. -      mem_bytes(TYPE_VEC,0,size*sizeof(Real));
  1229. -   }
  1230. -   
  1231. -   return (vector);
  1232. -}
  1233. -
  1234. -/* m_free -- returns MAT & asoociated memory back to memory heap */
  1235. -int    m_free(mat)
  1236. -MAT    *mat;
  1237. -{
  1238. -#ifdef SEGMENTED
  1239. -   int    i;
  1240. -#endif
  1241. -   
  1242. -   if ( mat==(MAT *)NULL || (int)(mat->m) < 0 ||
  1243. -       (int)(mat->n) < 0 )
  1244. -     /* don't trust it */
  1245. -     return (-1);
  1246. -   
  1247. -#ifndef SEGMENTED
  1248. -   if ( mat->base != (Real *)NULL ) {
  1249. -      if (mem_info_is_on()) {
  1250. -     mem_bytes(TYPE_MAT,mat->max_m*mat->max_n*sizeof(Real),0);
  1251. -      }
  1252. -      free((char *)(mat->base));
  1253. -   }
  1254. -#else
  1255. -   for ( i = 0; i < mat->max_m; i++ )
  1256. -     if ( mat->me[i] != (Real *)NULL ) {
  1257. -    if (mem_info_is_on()) {
  1258. -       mem_bytes(TYPE_MAT,mat->max_n*sizeof(Real),0);
  1259. -    }
  1260. -    free((char *)(mat->me[i]));
  1261. -     }
  1262. -#endif
  1263. -   if ( mat->me != (Real **)NULL ) {
  1264. -      if (mem_info_is_on()) {
  1265. -     mem_bytes(TYPE_MAT,mat->max_m*sizeof(Real *),0);
  1266. -      }
  1267. -      free((char *)(mat->me));
  1268. -   }
  1269. -   
  1270. -   if (mem_info_is_on()) {
  1271. -      mem_bytes(TYPE_MAT,sizeof(MAT),0);
  1272. -      mem_numvar(TYPE_MAT,-1);
  1273. -   }
  1274. -   free((char *)mat);
  1275. -   
  1276. -   return (0);
  1277. -}
  1278. -
  1279. -
  1280. -
  1281. -/* px_free -- returns PERM & asoociated memory back to memory heap */
  1282. -int    px_free(px)
  1283. -PERM    *px;
  1284. -{
  1285. -   if ( px==(PERM *)NULL || (int)(px->size) < 0 )
  1286. -     /* don't trust it */
  1287. -     return (-1);
  1288. -   
  1289. -   if ( px->pe == (u_int *)NULL ) {
  1290. -      if (mem_info_is_on()) {
  1291. -     mem_bytes(TYPE_PERM,sizeof(PERM),0);
  1292. -     mem_numvar(TYPE_PERM,-1);
  1293. -      }      
  1294. -      free((char *)px);
  1295. -   }
  1296. -   else
  1297. -   {
  1298. -      if (mem_info_is_on()) {
  1299. -     mem_bytes(TYPE_PERM,sizeof(PERM)+px->max_size*sizeof(u_int),0);
  1300. -     mem_numvar(TYPE_PERM,-1);
  1301. -      }
  1302. -      free((char *)px->pe);
  1303. -      free((char *)px);
  1304. -   }
  1305. -   
  1306. -   return (0);
  1307. -}
  1308. -
  1309. -
  1310. -
  1311. -/* v_free -- returns VEC & asoociated memory back to memory heap */
  1312. -int    v_free(vec)
  1313. -VEC    *vec;
  1314. -{
  1315. -   if ( vec==(VEC *)NULL || (int)(vec->dim) < 0 )
  1316. -     /* don't trust it */
  1317. -     return (-1);
  1318. -   
  1319. -   if ( vec->ve == (Real *)NULL ) {
  1320. -      if (mem_info_is_on()) {
  1321. -     mem_bytes(TYPE_VEC,sizeof(VEC),0);
  1322. -     mem_numvar(TYPE_VEC,-1);
  1323. -      }
  1324. -      free((char *)vec);
  1325. -   }
  1326. -   else
  1327. -   {
  1328. -      if (mem_info_is_on()) {
  1329. -     mem_bytes(TYPE_VEC,sizeof(VEC)+vec->max_dim*sizeof(Real),0);
  1330. -     mem_numvar(TYPE_VEC,-1);
  1331. -      }
  1332. -      free((char *)vec->ve);
  1333. -      free((char *)vec);
  1334. -   }
  1335. -   
  1336. -   return (0);
  1337. -}
  1338. -
  1339. -
  1340. -
  1341. -/* m_resize -- returns the matrix A of size new_m x new_n; A is zeroed
  1342. -   -- if A == NULL on entry then the effect is equivalent to m_get() */
  1343. -MAT    *m_resize(A,new_m,new_n)
  1344. -MAT    *A;
  1345. -int    new_m, new_n;
  1346. -{
  1347. -   int    i;
  1348. -   int    new_max_m, new_max_n, new_size, old_m, old_n;
  1349. -   
  1350. -   if (new_m < 0 || new_n < 0)
  1351. -     error(E_NEG,"m_resize");
  1352. -
  1353. -   if ( ! A )
  1354. -     return m_get(new_m,new_n);
  1355. -
  1356. -   /* nothing was changed */
  1357. -   if (new_m == A->m && new_n == A->n)
  1358. -     return A;
  1359. -
  1360. -   old_m = A->m;    old_n = A->n;
  1361. -   if ( new_m > A->max_m )
  1362. -   {    /* re-allocate A->me */
  1363. -      if (mem_info_is_on()) {
  1364. -     mem_bytes(TYPE_MAT,A->max_m*sizeof(Real *),
  1365. -              new_m*sizeof(Real *));
  1366. -      }
  1367. -
  1368. -      A->me = RENEW(A->me,new_m,Real *);
  1369. -      if ( ! A->me )
  1370. -    error(E_MEM,"m_resize");
  1371. -   }
  1372. -   new_max_m = max(new_m,A->max_m);
  1373. -   new_max_n = max(new_n,A->max_n);
  1374. -   
  1375. -#ifndef SEGMENTED
  1376. -   new_size = new_max_m*new_max_n;
  1377. -   if ( new_size > A->max_size )
  1378. -   {    /* re-allocate A->base */
  1379. -      if (mem_info_is_on()) {
  1380. -     mem_bytes(TYPE_MAT,A->max_m*A->max_n*sizeof(Real),
  1381. -              new_size*sizeof(Real));
  1382. -      }
  1383. -
  1384. -      A->base = RENEW(A->base,new_size,Real);
  1385. -      if ( ! A->base )
  1386. -    error(E_MEM,"m_resize");
  1387. -      A->max_size = new_size;
  1388. -   }
  1389. -   
  1390. -   /* now set up A->me[i] */
  1391. -   for ( i = 0; i < new_m; i++ )
  1392. -     A->me[i] = &(A->base[i*new_n]);
  1393. -   
  1394. -   /* now shift data in matrix */
  1395. -   if ( old_n > new_n )
  1396. -   {
  1397. -      for ( i = 1; i < min(old_m,new_m); i++ )
  1398. -    MEM_COPY((char *)&(A->base[i*old_n]),
  1399. -         (char *)&(A->base[i*new_n]),
  1400. -         sizeof(Real)*new_n);
  1401. -   }
  1402. -   else if ( old_n < new_n )
  1403. -   {
  1404. -      for ( i = (int)(min(old_m,new_m))-1; i > 0; i-- )
  1405. -      {   /* copy & then zero extra space */
  1406. -     MEM_COPY((char *)&(A->base[i*old_n]),
  1407. -          (char *)&(A->base[i*new_n]),
  1408. -          sizeof(Real)*old_n);
  1409. -     __zero__(&(A->base[i*new_n+old_n]),(new_n-old_n));
  1410. -      }
  1411. -      __zero__(&(A->base[old_n]),(new_n-old_n));
  1412. -      A->max_n = new_n;
  1413. -   }
  1414. -   /* zero out the new rows.. */
  1415. -   for ( i = old_m; i < new_m; i++ )
  1416. -     __zero__(&(A->base[i*new_n]),new_n);
  1417. -#else
  1418. -   if ( A->max_n < new_n )
  1419. -   {
  1420. -      Real    *tmp;
  1421. -      
  1422. -      for ( i = 0; i < A->max_m; i++ )
  1423. -      {
  1424. -     if (mem_info_is_on()) {
  1425. -        mem_bytes(TYPE_MAT,A->max_n*sizeof(Real),
  1426. -             new_max_n*sizeof(Real));
  1427. -     }    
  1428. -
  1429. -     if ( (tmp = RENEW(A->me[i],new_max_n,Real)) == NULL )
  1430. -       error(E_MEM,"m_resize");
  1431. -     else {    
  1432. -        A->me[i] = tmp;
  1433. -     }
  1434. -      }
  1435. -      for ( i = A->max_m; i < new_max_m; i++ )
  1436. -      {
  1437. -     if ( (tmp = NEW_A(new_max_n,Real)) == NULL )
  1438. -       error(E_MEM,"m_resize");
  1439. -     else {
  1440. -        A->me[i] = tmp;
  1441. -
  1442. -        if (mem_info_is_on()) {
  1443. -           mem_bytes(TYPE_MAT,0,new_max_n*sizeof(Real));
  1444. -        }        
  1445. -     }
  1446. -      }
  1447. -   }
  1448. -   else if ( A->max_m < new_m )
  1449. -   {
  1450. -      for ( i = A->max_m; i < new_m; i++ ) 
  1451. -    if ( (A->me[i] = NEW_A(new_max_n,Real)) == NULL )
  1452. -      error(E_MEM,"m_resize");
  1453. -    else if (mem_info_is_on()) {
  1454. -       mem_bytes(TYPE_MAT,0,new_max_n*sizeof(Real));
  1455. -    }
  1456. -      
  1457. -   }
  1458. -   
  1459. -   if ( old_n < new_n )
  1460. -   {
  1461. -      for ( i = 0; i < old_m; i++ )
  1462. -    __zero__(&(A->me[i][old_n]),new_n-old_n);
  1463. -   }
  1464. -   
  1465. -   /* zero out the new rows.. */
  1466. -   for ( i = old_m; i < new_m; i++ )
  1467. -     __zero__(A->me[i],new_n);
  1468. -#endif
  1469. -   
  1470. -   A->max_m = new_max_m;
  1471. -   A->max_n = new_max_n;
  1472. -   A->max_size = A->max_m*A->max_n;
  1473. -   A->m = new_m;    A->n = new_n;
  1474. -   
  1475. -   return A;
  1476. -}
  1477. -
  1478. -/* px_resize -- returns the permutation px with size new_size
  1479. -   -- px is set to the identity permutation */
  1480. -PERM    *px_resize(px,new_size)
  1481. -PERM    *px;
  1482. -int    new_size;
  1483. -{
  1484. -   int    i;
  1485. -   
  1486. -   if (new_size < 0)
  1487. -     error(E_NEG,"px_resize");
  1488. -
  1489. -   if ( ! px )
  1490. -     return px_get(new_size);
  1491. -   
  1492. -   /* nothing is changed */
  1493. -   if (new_size == px->size)
  1494. -     return px;
  1495. -
  1496. -   if ( new_size > px->max_size )
  1497. -   {
  1498. -      if (mem_info_is_on()) {
  1499. -     mem_bytes(TYPE_PERM,px->max_size*sizeof(u_int),
  1500. -              new_size*sizeof(u_int));
  1501. -      }
  1502. -      px->pe = RENEW(px->pe,new_size,u_int);
  1503. -      if ( ! px->pe )
  1504. -    error(E_MEM,"px_resize");
  1505. -      px->max_size = new_size;
  1506. -   }
  1507. -   if ( px->size <= new_size )
  1508. -     /* extend permutation */
  1509. -     for ( i = px->size; i < new_size; i++ )
  1510. -       px->pe[i] = i;
  1511. -   else
  1512. -     for ( i = 0; i < new_size; i++ )
  1513. -       px->pe[i] = i;
  1514. -   
  1515. -   px->size = new_size;
  1516. -   
  1517. -   return px;
  1518. -}
  1519. -
  1520. -/* v_resize -- returns the vector x with dim new_dim
  1521. -   -- x is set to the zero vector */
  1522. -VEC    *v_resize(x,new_dim)
  1523. -VEC    *x;
  1524. -int    new_dim;
  1525. -{
  1526. -   
  1527. -   if (new_dim < 0)
  1528. -     error(E_NEG,"v_resize");
  1529. -
  1530. -   if ( ! x )
  1531. -     return v_get(new_dim);
  1532. -
  1533. -   /* nothing is changed */
  1534. -   if (new_dim == x->dim)
  1535. -     return x;
  1536. -
  1537. -   if ( x->max_dim == 0 )    /* assume that it's from sub_vec */
  1538. -     return v_get(new_dim);
  1539. -   
  1540. -   if ( new_dim > x->max_dim )
  1541. -   {
  1542. -      if (mem_info_is_on()) { 
  1543. -     mem_bytes(TYPE_VEC,x->max_dim*sizeof(Real),
  1544. -             new_dim*sizeof(Real));
  1545. -      }
  1546. -
  1547. -      x->ve = RENEW(x->ve,new_dim,Real);
  1548. -      if ( ! x->ve )
  1549. -    error(E_MEM,"v_resize");
  1550. -      x->max_dim = new_dim;
  1551. -   }
  1552. -   
  1553. -   if ( new_dim > x->dim )
  1554. -     __zero__(&(x->ve[x->dim]),new_dim - x->dim);
  1555. -   x->dim = new_dim;
  1556. -   
  1557. -   return x;
  1558. -}
  1559. -
  1560. -
  1561. -
  1562. -
  1563. -/* Varying number of arguments */
  1564. -/* other functions of this type are in sparse.c and zmemory.c */
  1565. -
  1566. -
  1567. -
  1568. -#ifdef ANSI_C
  1569. -
  1570. -
  1571. -/* To allocate memory to many arguments. 
  1572. -   The function should be called:
  1573. -   v_get_vars(dim,&x,&y,&z,...,NULL);
  1574. -   where 
  1575. -     int dim;
  1576. -     VEC *x, *y, *z,...;
  1577. -     The last argument should be NULL ! 
  1578. -     dim is the length of vectors x,y,z,...
  1579. -     returned value is equal to the number of allocated variables
  1580. -     Other gec_... functions are similar.
  1581. -*/
  1582. -
  1583. -int v_get_vars(int dim,...) 
  1584. -{
  1585. -   va_list ap;
  1586. -   int i=0;
  1587. -   VEC **par;
  1588. -   
  1589. -   va_start(ap, dim);
  1590. -   while (par = va_arg(ap,VEC **)) {   /* NULL ends the list*/
  1591. -      *par = v_get(dim);
  1592. -      i++;
  1593. -   } 
  1594. -
  1595. -   va_end(ap);
  1596. -   return i;
  1597. -}
  1598. -
  1599. -
  1600. -int iv_get_vars(int dim,...) 
  1601. -{
  1602. -   va_list ap;
  1603. -   int i=0;
  1604. -   IVEC **par;
  1605. -   
  1606. -   va_start(ap, dim);
  1607. -   while (par = va_arg(ap,IVEC **)) {   /* NULL ends the list*/
  1608. -      *par = iv_get(dim);
  1609. -      i++;
  1610. -   } 
  1611. -
  1612. -   va_end(ap);
  1613. -   return i;
  1614. -}
  1615. -
  1616. -int m_get_vars(int m,int n,...) 
  1617. -{
  1618. -   va_list ap;
  1619. -   int i=0;
  1620. -   MAT **par;
  1621. -   
  1622. -   va_start(ap, n);
  1623. -   while (par = va_arg(ap,MAT **)) {   /* NULL ends the list*/
  1624. -      *par = m_get(m,n);
  1625. -      i++;
  1626. -   } 
  1627. -
  1628. -   va_end(ap);
  1629. -   return i;
  1630. -}
  1631. -
  1632. -int px_get_vars(int dim,...) 
  1633. -{
  1634. -   va_list ap;
  1635. -   int i=0;
  1636. -   PERM **par;
  1637. -   
  1638. -   va_start(ap, dim);
  1639. -   while (par = va_arg(ap,PERM **)) {   /* NULL ends the list*/
  1640. -      *par = px_get(dim);
  1641. -      i++;
  1642. -   } 
  1643. -
  1644. -   va_end(ap);
  1645. -   return i;
  1646. -}
  1647. -
  1648. -
  1649. -
  1650. -/* To resize memory for many arguments. 
  1651. -   The function should be called:
  1652. -   v_resize_vars(new_dim,&x,&y,&z,...,NULL);
  1653. -   where 
  1654. -     int new_dim;
  1655. -     VEC *x, *y, *z,...;
  1656. -     The last argument should be NULL ! 
  1657. -     rdim is the resized length of vectors x,y,z,...
  1658. -     returned value is equal to the number of allocated variables.
  1659. -     If one of x,y,z,.. arguments is NULL then memory is allocated to this 
  1660. -     argument. 
  1661. -     Other *_resize_list() functions are similar.
  1662. -*/
  1663. -
  1664. -int v_resize_vars(int new_dim,...)
  1665. -{
  1666. -   va_list ap;
  1667. -   int i=0;
  1668. -   VEC **par;
  1669. -   
  1670. -   va_start(ap, new_dim);
  1671. -   while (par = va_arg(ap,VEC **)) {   /* NULL ends the list*/
  1672. -      *par = v_resize(*par,new_dim);
  1673. -      i++;
  1674. -   } 
  1675. -
  1676. -   va_end(ap);
  1677. -   return i;
  1678. -}
  1679. -
  1680. -
  1681. -
  1682. -int iv_resize_vars(int new_dim,...) 
  1683. -{
  1684. -   va_list ap;
  1685. -   int i=0;
  1686. -   IVEC **par;
  1687. -   
  1688. -   va_start(ap, new_dim);
  1689. -   while (par = va_arg(ap,IVEC **)) {   /* NULL ends the list*/
  1690. -      *par = iv_resize(*par,new_dim);
  1691. -      i++;
  1692. -   } 
  1693. -
  1694. -   va_end(ap);
  1695. -   return i;
  1696. -}
  1697. -
  1698. -int m_resize_vars(int m,int n,...) 
  1699. -{
  1700. -   va_list ap;
  1701. -   int i=0;
  1702. -   MAT **par;
  1703. -   
  1704. -   va_start(ap, n);
  1705. -   while (par = va_arg(ap,MAT **)) {   /* NULL ends the list*/
  1706. -      *par = m_resize(*par,m,n);
  1707. -      i++;
  1708. -   } 
  1709. -
  1710. -   va_end(ap);
  1711. -   return i;
  1712. -}
  1713. -
  1714. -
  1715. -int px_resize_vars(int new_dim,...) 
  1716. -{
  1717. -   va_list ap;
  1718. -   int i=0;
  1719. -   PERM **par;
  1720. -   
  1721. -   va_start(ap, new_dim);
  1722. -   while (par = va_arg(ap,PERM **)) {   /* NULL ends the list*/
  1723. -      *par = px_resize(*par,new_dim);
  1724. -      i++;
  1725. -   } 
  1726. -
  1727. -   va_end(ap);
  1728. -   return i;
  1729. -}
  1730. -
  1731. -/* To deallocate memory for many arguments. 
  1732. -   The function should be called:
  1733. -   v_free_vars(&x,&y,&z,...,NULL);
  1734. -   where 
  1735. -     VEC *x, *y, *z,...;
  1736. -     The last argument should be NULL ! 
  1737. -     There must be at least one not NULL argument.
  1738. -     returned value is equal to the number of allocated variables.
  1739. -     Returned value of x,y,z,.. is VNULL.
  1740. -     Other *_free_list() functions are similar.
  1741. -*/
  1742. -
  1743. -
  1744. -int v_free_vars(VEC **pv,...)
  1745. -{
  1746. -   va_list ap;
  1747. -   int i=1;
  1748. -   VEC **par;
  1749. -   
  1750. -   v_free(*pv);
  1751. -   *pv = VNULL;
  1752. -   va_start(ap, pv);
  1753. -   while (par = va_arg(ap,VEC **)) {   /* NULL ends the list*/
  1754. -      v_free(*par); 
  1755. -      *par = VNULL;
  1756. -      i++;
  1757. -   } 
  1758. -
  1759. -   va_end(ap);
  1760. -   return i;
  1761. -}
  1762. -
  1763. -
  1764. -int iv_free_vars(IVEC **ipv,...)
  1765. -{
  1766. -   va_list ap;
  1767. -   int i=1;
  1768. -   IVEC **par;
  1769. -   
  1770. -   iv_free(*ipv);
  1771. -   *ipv = IVNULL;
  1772. -   va_start(ap, ipv);
  1773. -   while (par = va_arg(ap,IVEC **)) {   /* NULL ends the list*/
  1774. -      iv_free(*par); 
  1775. -      *par = IVNULL;
  1776. -      i++;
  1777. -   } 
  1778. -
  1779. -   va_end(ap);
  1780. -   return i;
  1781. -}
  1782. -
  1783. -
  1784. -int px_free_vars(PERM **vpx,...)
  1785. -{
  1786. -   va_list ap;
  1787. -   int i=1;
  1788. -   PERM **par;
  1789. -   
  1790. -   px_free(*vpx);
  1791. -   *vpx = PNULL;
  1792. -   va_start(ap, vpx);
  1793. -   while (par = va_arg(ap,PERM **)) {   /* NULL ends the list*/
  1794. -      px_free(*par); 
  1795. -      *par = PNULL;
  1796. -      i++;
  1797. -   } 
  1798. -
  1799. -   va_end(ap);
  1800. -   return i;
  1801. -}
  1802. -
  1803. -int m_free_vars(MAT **va,...)
  1804. -{
  1805. -   va_list ap;
  1806. -   int i=1;
  1807. -   MAT **par;
  1808. -   
  1809. -   m_free(*va);
  1810. -   *va = MNULL;
  1811. -   va_start(ap, va);
  1812. -   while (par = va_arg(ap,MAT **)) {   /* NULL ends the list*/
  1813. -      m_free(*par); 
  1814. -      *par = MNULL;
  1815. -      i++;
  1816. -   } 
  1817. -
  1818. -   va_end(ap);
  1819. -   return i;
  1820. -}
  1821. -
  1822. -
  1823. -#elif VARARGS
  1824. -/* old varargs is used */
  1825. -
  1826. -
  1827. -
  1828. -/* To allocate memory to many arguments. 
  1829. -   The function should be called:
  1830. -   v_get_vars(dim,&x,&y,&z,...,VNULL);
  1831. -   where 
  1832. -     int dim;
  1833. -     VEC *x, *y, *z,...;
  1834. -     The last argument should be VNULL ! 
  1835. -     dim is the length of vectors x,y,z,...
  1836. -*/
  1837. -
  1838. -int v_get_vars(va_alist) va_dcl
  1839. -{
  1840. -   va_list ap;
  1841. -   int dim,i=0;
  1842. -   VEC **par;
  1843. -   
  1844. -   va_start(ap);
  1845. -   dim = va_arg(ap,int);
  1846. -   while (par = va_arg(ap,VEC **)) {   /* NULL ends the list*/
  1847. -      *par = v_get(dim);
  1848. -      i++;
  1849. -   } 
  1850. -
  1851. -   va_end(ap);
  1852. -   return i;
  1853. -}
  1854. -
  1855. -
  1856. -int iv_get_vars(va_alist) va_dcl
  1857. -{
  1858. -   va_list ap;
  1859. -   int i=0, dim;
  1860. -   IVEC **par;
  1861. -   
  1862. -   va_start(ap);
  1863. -   dim = va_arg(ap,int);
  1864. -   while (par = va_arg(ap,IVEC **)) {   /* NULL ends the list*/
  1865. -      *par = iv_get(dim);
  1866. -      i++;
  1867. -   } 
  1868. -
  1869. -   va_end(ap);
  1870. -   return i;
  1871. -}
  1872. -
  1873. -int m_get_vars(va_alist) va_dcl
  1874. -{
  1875. -   va_list ap;
  1876. -   int i=0, n, m;
  1877. -   MAT **par;
  1878. -   
  1879. -   va_start(ap);
  1880. -   m = va_arg(ap,int);
  1881. -   n = va_arg(ap,int);
  1882. -   while (par = va_arg(ap,MAT **)) {   /* NULL ends the list*/
  1883. -      *par = m_get(m,n);
  1884. -      i++;
  1885. -   } 
  1886. -
  1887. -   va_end(ap);
  1888. -   return i;
  1889. -}
  1890. -
  1891. -
  1892. -
  1893. -int px_get_vars(va_alist) va_dcl
  1894. -{
  1895. -   va_list ap;
  1896. -   int i=0, dim;
  1897. -   PERM **par;
  1898. -   
  1899. -   va_start(ap);
  1900. -   dim = va_arg(ap,int);
  1901. -   while (par = va_arg(ap,PERM **)) {   /* NULL ends the list*/
  1902. -      *par = px_get(dim);
  1903. -      i++;
  1904. -   } 
  1905. -
  1906. -   va_end(ap);
  1907. -   return i;
  1908. -}
  1909. -
  1910. -
  1911. -
  1912. -/* To resize memory for many arguments. 
  1913. -   The function should be called:
  1914. -   v_resize_vars(new_dim,&x,&y,&z,...,NULL);
  1915. -   where 
  1916. -     int new_dim;
  1917. -     VEC *x, *y, *z,...;
  1918. -     The last argument should be NULL ! 
  1919. -     rdim is the resized length of vectors x,y,z,...
  1920. -     returned value is equal to the number of allocated variables.
  1921. -     If one of x,y,z,.. arguments is NULL then memory is allocated to this 
  1922. -     argument. 
  1923. -     Other *_resize_list() functions are similar.
  1924. -*/
  1925. -
  1926. -int v_resize_vars(va_alist) va_dcl
  1927. -{
  1928. -   va_list ap;
  1929. -   int i=0, new_dim;
  1930. -   VEC **par;
  1931. -   
  1932. -   va_start(ap);
  1933. -   new_dim = va_arg(ap,int);
  1934. -   while (par = va_arg(ap,VEC **)) {   /* NULL ends the list*/
  1935. -      *par = v_resize(*par,new_dim);
  1936. -      i++;
  1937. -   } 
  1938. -
  1939. -   va_end(ap);
  1940. -   return i;
  1941. -}
  1942. -
  1943. -
  1944. -
  1945. -int iv_resize_vars(va_alist) va_dcl
  1946. -{
  1947. -   va_list ap;
  1948. -   int i=0, new_dim;
  1949. -   IVEC **par;
  1950. -   
  1951. -   va_start(ap);
  1952. -   new_dim = va_arg(ap,int);
  1953. -   while (par = va_arg(ap,IVEC **)) {   /* NULL ends the list*/
  1954. -      *par = iv_resize(*par,new_dim);
  1955. -      i++;
  1956. -   } 
  1957. -
  1958. -   va_end(ap);
  1959. -   return i;
  1960. -}
  1961. -
  1962. -int m_resize_vars(va_alist) va_dcl
  1963. -{
  1964. -   va_list ap;
  1965. -   int i=0, m, n;
  1966. -   MAT **par;
  1967. -   
  1968. -   va_start(ap);
  1969. -   m = va_arg(ap,int);
  1970. -   n = va_arg(ap,int);
  1971. -   while (par = va_arg(ap,MAT **)) {   /* NULL ends the list*/
  1972. -      *par = m_resize(*par,m,n);
  1973. -      i++;
  1974. -   } 
  1975. -
  1976. -   va_end(ap);
  1977. -   return i;
  1978. -}
  1979. -
  1980. -int px_resize_vars(va_alist) va_dcl
  1981. -{
  1982. -   va_list ap;
  1983. -   int i=0, new_dim;
  1984. -   PERM **par;
  1985. -   
  1986. -   va_start(ap);
  1987. -   new_dim = va_arg(ap,int);
  1988. -   while (par = va_arg(ap,PERM **)) {   /* NULL ends the list*/
  1989. -      *par = px_resize(*par,new_dim);
  1990. -      i++;
  1991. -   } 
  1992. -
  1993. -   va_end(ap);
  1994. -   return i;
  1995. -}
  1996. -
  1997. -
  1998. -/* To deallocate memory for many arguments. 
  1999. -   The function should be called:
  2000. -   v_free_vars(&x,&y,&z,...,NULL);
  2001. -   where 
  2002. -     VEC *x, *y, *z,...;
  2003. -     The last argument should be NULL ! 
  2004. -     returned value is equal to the number of allocated variables.
  2005. -     Returned value of x,y,z,.. is VNULL.
  2006. -     Other *_free_list() functions are similar.
  2007. -*/
  2008. -
  2009. -
  2010. -int v_free_vars(va_alist) va_dcl
  2011. -{
  2012. -   va_list ap;
  2013. -   int i=0;
  2014. -   VEC **par;
  2015. -   
  2016. -   va_start(ap);
  2017. -   while (par = va_arg(ap,VEC **)) {   /* NULL ends the list*/
  2018. -      v_free(*par); 
  2019. -      *par = VNULL;
  2020. -      i++;
  2021. -   } 
  2022. -
  2023. -   va_end(ap);
  2024. -   return i;
  2025. -}
  2026. -
  2027. -
  2028. -
  2029. -int iv_free_vars(va_alist) va_dcl
  2030. -{
  2031. -   va_list ap;
  2032. -   int i=0;
  2033. -   IVEC **par;
  2034. -   
  2035. -   va_start(ap);
  2036. -   while (par = va_arg(ap,IVEC **)) {   /* NULL ends the list*/
  2037. -      iv_free(*par); 
  2038. -      *par = IVNULL;
  2039. -      i++;
  2040. -   } 
  2041. -
  2042. -   va_end(ap);
  2043. -   return i;
  2044. -}
  2045. -
  2046. -
  2047. -int px_free_vars(va_alist) va_dcl
  2048. -{
  2049. -   va_list ap;
  2050. -   int i=0;
  2051. -   PERM **par;
  2052. -   
  2053. -   va_start(ap);
  2054. -   while (par = va_arg(ap,PERM **)) {   /* NULL ends the list*/
  2055. -      px_free(*par); 
  2056. -      *par = PNULL;
  2057. -      i++;
  2058. -   } 
  2059. -
  2060. -   va_end(ap);
  2061. -   return i;
  2062. -}
  2063. -
  2064. -int m_free_vars(va_alist) va_dcl
  2065. -{
  2066. -   va_list ap;
  2067. -   int i=0;
  2068. -   MAT **par;
  2069. -   
  2070. -   va_start(ap);
  2071. -   while (par = va_arg(ap,MAT **)) {   /* NULL ends the list*/
  2072. -      m_free(*par); 
  2073. -      *par = MNULL;
  2074. -      i++;
  2075. -   } 
  2076. -
  2077. -   va_end(ap);
  2078. -   return i;
  2079. -}
  2080. -
  2081. -
  2082. -
  2083. -#endif /* VARARGS */
  2084. -  
  2085. -
  2086. //GO.SYSIN DD memory.c
  2087. echo vecop.c 1>&2
  2088. sed >vecop.c <<'//GO.SYSIN DD vecop.c' 's/^-//'
  2089. -
  2090. -/**************************************************************************
  2091. -**
  2092. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  2093. -**
  2094. -**                 Meschach Library
  2095. -** 
  2096. -** This Meschach Library is provided "as is" without any express 
  2097. -** or implied warranty of any kind with respect to this software. 
  2098. -** In particular the authors shall not be liable for any direct, 
  2099. -** indirect, special, incidental or consequential damages arising 
  2100. -** in any way from use of the software.
  2101. -** 
  2102. -** Everyone is granted permission to copy, modify and redistribute this
  2103. -** Meschach Library, provided:
  2104. -**  1.  All copies contain this copyright notice.
  2105. -**  2.  All modified copies shall carry a notice stating who
  2106. -**      made the last modification and the date of such modification.
  2107. -**  3.  No charge is made for this software or works derived from it.  
  2108. -**      This clause shall not be construed as constraining other software
  2109. -**      distributed on the same medium as this software, nor is a
  2110. -**      distribution fee considered a charge.
  2111. -**
  2112. -***************************************************************************/
  2113. -
  2114. -
  2115. -/* vecop.c 1.3 8/18/87 */
  2116. -
  2117. -#include    <stdio.h>
  2118. -#include    "matrix.h"
  2119. -
  2120. -static    char    rcsid[] = "$Id: vecop.c,v 1.4 1994/03/08 05:50:39 des Exp $";
  2121. -
  2122. -
  2123. -/* _in_prod -- inner product of two vectors from i0 downwards */
  2124. -double    _in_prod(a,b,i0)
  2125. -VEC    *a,*b;
  2126. -u_int    i0;
  2127. -{
  2128. -    u_int    limit;
  2129. -    /* Real    *a_v, *b_v; */
  2130. -    /* register Real    sum; */
  2131. -
  2132. -    if ( a==(VEC *)NULL || b==(VEC *)NULL )
  2133. -        error(E_NULL,"_in_prod");
  2134. -    limit = min(a->dim,b->dim);
  2135. -    if ( i0 > limit )
  2136. -        error(E_BOUNDS,"_in_prod");
  2137. -
  2138. -    return __ip__(&(a->ve[i0]),&(b->ve[i0]),(int)(limit-i0));
  2139. -    /*****************************************
  2140. -    a_v = &(a->ve[i0]);        b_v = &(b->ve[i0]);
  2141. -    for ( i=i0; i<limit; i++ )
  2142. -        sum += a_v[i]*b_v[i];
  2143. -        sum += (*a_v++)*(*b_v++);
  2144. -
  2145. -    return (double)sum;
  2146. -    ******************************************/
  2147. -}
  2148. -
  2149. -/* sv_mlt -- scalar-vector multiply -- may be in-situ */
  2150. -VEC    *sv_mlt(scalar,vector,out)
  2151. -double    scalar;
  2152. -VEC    *vector,*out;
  2153. -{
  2154. -    /* u_int    dim, i; */
  2155. -    /* Real    *out_ve, *vec_ve; */
  2156. -
  2157. -    if ( vector==(VEC *)NULL )
  2158. -        error(E_NULL,"sv_mlt");
  2159. -    if ( out==(VEC *)NULL || out->dim != vector->dim )
  2160. -        out = v_resize(out,vector->dim);
  2161. -    if ( scalar == 0.0 )
  2162. -        return v_zero(out);
  2163. -    if ( scalar == 1.0 )
  2164. -        return v_copy(vector,out);
  2165. -
  2166. -    __smlt__(vector->ve,(double)scalar,out->ve,(int)(vector->dim));
  2167. -    /**************************************************
  2168. -    dim = vector->dim;
  2169. -    out_ve = out->ve;    vec_ve = vector->ve;
  2170. -    for ( i=0; i<dim; i++ )
  2171. -        out->ve[i] = scalar*vector->ve[i];
  2172. -        (*out_ve++) = scalar*(*vec_ve++);
  2173. -    **************************************************/
  2174. -    return (out);
  2175. -}
  2176. -
  2177. -/* v_add -- vector addition -- may be in-situ */
  2178. -VEC    *v_add(vec1,vec2,out)
  2179. -VEC    *vec1,*vec2,*out;
  2180. -{
  2181. -    u_int    dim;
  2182. -    /* Real    *out_ve, *vec1_ve, *vec2_ve; */
  2183. -
  2184. -    if ( vec1==(VEC *)NULL || vec2==(VEC *)NULL )
  2185. -        error(E_NULL,"v_add");
  2186. -    if ( vec1->dim != vec2->dim )
  2187. -        error(E_SIZES,"v_add");
  2188. -    if ( out==(VEC *)NULL || out->dim != vec1->dim )
  2189. -        out = v_resize(out,vec1->dim);
  2190. -    dim = vec1->dim;
  2191. -    __add__(vec1->ve,vec2->ve,out->ve,(int)dim);
  2192. -    /************************************************************
  2193. -    out_ve = out->ve;    vec1_ve = vec1->ve;    vec2_ve = vec2->ve;
  2194. -    for ( i=0; i<dim; i++ )
  2195. -        out->ve[i] = vec1->ve[i]+vec2->ve[i];
  2196. -        (*out_ve++) = (*vec1_ve++) + (*vec2_ve++);
  2197. -    ************************************************************/
  2198. -
  2199. -    return (out);
  2200. -}
  2201. -
  2202. -/* v_mltadd -- scalar/vector multiplication and addition
  2203. -        -- out = v1 + scale.v2        */
  2204. -VEC    *v_mltadd(v1,v2,scale,out)
  2205. -VEC    *v1,*v2,*out;
  2206. -double    scale;
  2207. -{
  2208. -    /* register u_int    dim, i; */
  2209. -    /* Real    *out_ve, *v1_ve, *v2_ve; */
  2210. -
  2211. -    if ( v1==(VEC *)NULL || v2==(VEC *)NULL )
  2212. -        error(E_NULL,"v_mltadd");
  2213. -    if ( v1->dim != v2->dim )
  2214. -        error(E_SIZES,"v_mltadd");
  2215. -    if ( scale == 0.0 )
  2216. -        return v_copy(v1,out);
  2217. -    if ( scale == 1.0 )
  2218. -        return v_add(v1,v2,out);
  2219. -
  2220. -    if ( v2 != out )
  2221. -    {
  2222. -        tracecatch(out = v_copy(v1,out),"v_mltadd");
  2223. -
  2224. -        /* dim = v1->dim; */
  2225. -        __mltadd__(out->ve,v2->ve,scale,(int)(v1->dim));
  2226. -    }
  2227. -    else
  2228. -    {
  2229. -        tracecatch(out = sv_mlt(scale,v2,out),"v_mltadd");
  2230. -        out = v_add(v1,out,out);
  2231. -    }
  2232. -    /************************************************************
  2233. -    out_ve = out->ve;    v1_ve = v1->ve;        v2_ve = v2->ve;
  2234. -    for ( i=0; i < dim ; i++ )
  2235. -        out->ve[i] = v1->ve[i] + scale*v2->ve[i];
  2236. -        (*out_ve++) = (*v1_ve++) + scale*(*v2_ve++);
  2237. -    ************************************************************/
  2238. -
  2239. -    return (out);
  2240. -}
  2241. -
  2242. -/* v_sub -- vector subtraction -- may be in-situ */
  2243. -VEC    *v_sub(vec1,vec2,out)
  2244. -VEC    *vec1,*vec2,*out;
  2245. -{
  2246. -    /* u_int    i, dim; */
  2247. -    /* Real    *out_ve, *vec1_ve, *vec2_ve; */
  2248. -
  2249. -    if ( vec1==(VEC *)NULL || vec2==(VEC *)NULL )
  2250. -        error(E_NULL,"v_sub");
  2251. -    if ( vec1->dim != vec2->dim )
  2252. -        error(E_SIZES,"v_sub");
  2253. -    if ( out==(VEC *)NULL || out->dim != vec1->dim )
  2254. -        out = v_resize(out,vec1->dim);
  2255. -
  2256. -    __sub__(vec1->ve,vec2->ve,out->ve,(int)(vec1->dim));
  2257. -    /************************************************************
  2258. -    dim = vec1->dim;
  2259. -    out_ve = out->ve;    vec1_ve = vec1->ve;    vec2_ve = vec2->ve;
  2260. -    for ( i=0; i<dim; i++ )
  2261. -        out->ve[i] = vec1->ve[i]-vec2->ve[i];
  2262. -        (*out_ve++) = (*vec1_ve++) - (*vec2_ve++);
  2263. -    ************************************************************/
  2264. -
  2265. -    return (out);
  2266. -}
  2267. -
  2268. -/* v_map -- maps function f over components of x: out[i] = f(x[i])
  2269. -    -- _v_map sets out[i] = f(params,x[i]) */
  2270. -VEC    *v_map(f,x,out)
  2271. -#ifdef PROTOTYPES_IN_STRUCT
  2272. -double    (*f)(double);
  2273. -#else
  2274. -double    (*f)();
  2275. -#endif
  2276. -VEC    *x, *out;
  2277. -{
  2278. -    Real    *x_ve, *out_ve;
  2279. -    int    i, dim;
  2280. -
  2281. -    if ( ! x || ! f )
  2282. -        error(E_NULL,"v_map");
  2283. -    if ( ! out || out->dim != x->dim )
  2284. -        out = v_resize(out,x->dim);
  2285. -
  2286. -    dim = x->dim;    x_ve = x->ve;    out_ve = out->ve;
  2287. -    for ( i = 0; i < dim; i++ )
  2288. -        *out_ve++ = (*f)(*x_ve++);
  2289. -
  2290. -    return out;
  2291. -}
  2292. -
  2293. -VEC    *_v_map(f,params,x,out)
  2294. -#ifdef PROTOTYPES_IN_STRUCT
  2295. -double    (*f)(void *,double);
  2296. -#else
  2297. -double    (*f)();
  2298. -#endif
  2299. -VEC    *x, *out;
  2300. -void    *params;
  2301. -{
  2302. -    Real    *x_ve, *out_ve;
  2303. -    int    i, dim;
  2304. -
  2305. -    if ( ! x || ! f )
  2306. -        error(E_NULL,"_v_map");
  2307. -    if ( ! out || out->dim != x->dim )
  2308. -        out = v_resize(out,x->dim);
  2309. -
  2310. -    dim = x->dim;    x_ve = x->ve;    out_ve = out->ve;
  2311. -    for ( i = 0; i < dim; i++ )
  2312. -        *out_ve++ = (*f)(params,*x_ve++);
  2313. -
  2314. -    return out;
  2315. -}
  2316. -
  2317. -/* v_lincomb -- returns sum_i a[i].v[i], a[i] real, v[i] vectors */
  2318. -VEC    *v_lincomb(n,v,a,out)
  2319. -int    n;    /* number of a's and v's */
  2320. -Real    a[];
  2321. -VEC    *v[], *out;
  2322. -{
  2323. -    int    i;
  2324. -
  2325. -    if ( ! a || ! v )
  2326. -        error(E_NULL,"v_lincomb");
  2327. -    if ( n <= 0 )
  2328. -        return VNULL;
  2329. -
  2330. -    for ( i = 1; i < n; i++ )
  2331. -        if ( out == v[i] )
  2332. -            error(E_INSITU,"v_lincomb");
  2333. -
  2334. -    out = sv_mlt(a[0],v[0],out);
  2335. -    for ( i = 1; i < n; i++ )
  2336. -    {
  2337. -        if ( ! v[i] )
  2338. -            error(E_NULL,"v_lincomb");
  2339. -        if ( v[i]->dim != out->dim )
  2340. -            error(E_SIZES,"v_lincomb");
  2341. -        out = v_mltadd(out,v[i],a[i],out);
  2342. -    }
  2343. -
  2344. -    return out;
  2345. -}
  2346. -
  2347. -
  2348. -
  2349. -#ifdef ANSI_C
  2350. -
  2351. -/* v_linlist -- linear combinations taken from a list of arguments;
  2352. -   calling:
  2353. -      v_linlist(out,v1,a1,v2,a2,...,vn,an,NULL);
  2354. -   where vi are vectors (VEC *) and ai are numbers (double)
  2355. -*/
  2356. -VEC  *v_linlist(VEC *out,VEC *v1,double a1,...)
  2357. -{
  2358. -   va_list ap;
  2359. -   VEC *par;
  2360. -   double a_par;
  2361. -
  2362. -   if ( ! v1 )
  2363. -     return VNULL;
  2364. -   
  2365. -   va_start(ap, a1);
  2366. -   out = sv_mlt(a1,v1,out);
  2367. -   
  2368. -   while (par = va_arg(ap,VEC *)) {   /* NULL ends the list*/
  2369. -      a_par = va_arg(ap,double);
  2370. -      if (a_par == 0.0) continue;
  2371. -      if ( out == par )        
  2372. -    error(E_INSITU,"v_linlist");
  2373. -      if ( out->dim != par->dim )    
  2374. -    error(E_SIZES,"v_linlist");
  2375. -
  2376. -      if (a_par == 1.0)
  2377. -    out = v_add(out,par,out);
  2378. -      else if (a_par == -1.0)
  2379. -    out = v_sub(out,par,out);
  2380. -      else
  2381. -    out = v_mltadd(out,par,a_par,out); 
  2382. -   } 
  2383. -   
  2384. -   va_end(ap);
  2385. -   return out;
  2386. -}
  2387. -#elif VARARGS
  2388. -
  2389. -
  2390. -/* v_linlist -- linear combinations taken from a list of arguments;
  2391. -   calling:
  2392. -      v_linlist(out,v1,a1,v2,a2,...,vn,an,NULL);
  2393. -   where vi are vectors (VEC *) and ai are numbers (double)
  2394. -*/
  2395. -VEC  *v_linlist(va_alist) va_dcl
  2396. -{
  2397. -   va_list ap;
  2398. -   VEC *par, *out;
  2399. -   double a_par;
  2400. -
  2401. -   va_start(ap);
  2402. -   out = va_arg(ap,VEC *);
  2403. -   par = va_arg(ap,VEC *);
  2404. -   if ( ! par ) {
  2405. -      va_end(ap);
  2406. -      return VNULL;
  2407. -   }
  2408. -   
  2409. -   a_par = va_arg(ap,double);
  2410. -   out = sv_mlt(a_par,par,out);
  2411. -   
  2412. -   while (par = va_arg(ap,VEC *)) {   /* NULL ends the list*/
  2413. -      a_par = va_arg(ap,double);
  2414. -      if (a_par == 0.0) continue;
  2415. -      if ( out == par )        
  2416. -    error(E_INSITU,"v_linlist");
  2417. -      if ( out->dim != par->dim )    
  2418. -    error(E_SIZES,"v_linlist");
  2419. -
  2420. -      if (a_par == 1.0)
  2421. -    out = v_add(out,par,out);
  2422. -      else if (a_par == -1.0)
  2423. -    out = v_sub(out,par,out);
  2424. -      else
  2425. -    out = v_mltadd(out,par,a_par,out); 
  2426. -   } 
  2427. -   
  2428. -   va_end(ap);
  2429. -   return out;
  2430. -}
  2431. -
  2432. -#endif
  2433. -  
  2434. -
  2435. -
  2436. -
  2437. -
  2438. -/* v_star -- computes componentwise (Hadamard) product of x1 and x2
  2439. -    -- result out is returned */
  2440. -VEC    *v_star(x1, x2, out)
  2441. -VEC    *x1, *x2, *out;
  2442. -{
  2443. -    int        i;
  2444. -
  2445. -    if ( ! x1 || ! x2 )
  2446. -    error(E_NULL,"v_star");
  2447. -    if ( x1->dim != x2->dim )
  2448. -    error(E_SIZES,"v_star");
  2449. -    out = v_resize(out,x1->dim);
  2450. -
  2451. -    for ( i = 0; i < x1->dim; i++ )
  2452. -    out->ve[i] = x1->ve[i] * x2->ve[i];
  2453. -
  2454. -    return out;
  2455. -}
  2456. -
  2457. -/* v_slash -- computes componentwise ratio of x2 and x1
  2458. -    -- out[i] = x2[i] / x1[i]
  2459. -    -- if x1[i] == 0 for some i, then raise E_SING error
  2460. -    -- result out is returned */
  2461. -VEC    *v_slash(x1, x2, out)
  2462. -VEC    *x1, *x2, *out;
  2463. -{
  2464. -    int        i;
  2465. -    Real    tmp;
  2466. -
  2467. -    if ( ! x1 || ! x2 )
  2468. -    error(E_NULL,"v_slash");
  2469. -    if ( x1->dim != x2->dim )
  2470. -    error(E_SIZES,"v_slash");
  2471. -    out = v_resize(out,x1->dim);
  2472. -
  2473. -    for ( i = 0; i < x1->dim; i++ )
  2474. -    {
  2475. -    tmp = x1->ve[i];
  2476. -    if ( tmp == 0.0 )
  2477. -        error(E_SING,"v_slash");
  2478. -    out->ve[i] = x2->ve[i] / tmp;
  2479. -    }
  2480. -
  2481. -    return out;
  2482. -}
  2483. -
  2484. -/* v_min -- computes minimum component of x, which is returned
  2485. -    -- also sets min_idx to the index of this minimum */
  2486. -double    v_min(x, min_idx)
  2487. -VEC    *x;
  2488. -int    *min_idx;
  2489. -{
  2490. -    int        i, i_min;
  2491. -    Real    min_val, tmp;
  2492. -
  2493. -    if ( ! x )
  2494. -    error(E_NULL,"v_min");
  2495. -    if ( x->dim <= 0 )
  2496. -    error(E_SIZES,"v_min");
  2497. -    i_min = 0;
  2498. -    min_val = x->ve[0];
  2499. -    for ( i = 1; i < x->dim; i++ )
  2500. -    {
  2501. -    tmp = x->ve[i];
  2502. -    if ( tmp < min_val )
  2503. -    {
  2504. -        min_val = tmp;
  2505. -        i_min = i;
  2506. -    }
  2507. -    }
  2508. -
  2509. -    if ( min_idx != NULL )
  2510. -    *min_idx = i_min;
  2511. -    return min_val;
  2512. -}
  2513. -
  2514. -/* v_max -- computes maximum component of x, which is returned
  2515. -    -- also sets max_idx to the index of this maximum */
  2516. -double    v_max(x, max_idx)
  2517. -VEC    *x;
  2518. -int    *max_idx;
  2519. -{
  2520. -    int        i, i_max;
  2521. -    Real    max_val, tmp;
  2522. -
  2523. -    if ( ! x )
  2524. -    error(E_NULL,"v_max");
  2525. -    if ( x->dim <= 0 )
  2526. -    error(E_SIZES,"v_max");
  2527. -    i_max = 0;
  2528. -    max_val = x->ve[0];
  2529. -    for ( i = 1; i < x->dim; i++ )
  2530. -    {
  2531. -    tmp = x->ve[i];
  2532. -    if ( tmp > max_val )
  2533. -    {
  2534. -        max_val = tmp;
  2535. -        i_max = i;
  2536. -    }
  2537. -    }
  2538. -
  2539. -    if ( max_idx != NULL )
  2540. -    *max_idx = i_max;
  2541. -    return max_val;
  2542. -}
  2543. -
  2544. -#define    MAX_STACK    60
  2545. -
  2546. -
  2547. -/* v_sort -- sorts vector x, and generates permutation that gives the order
  2548. -    of the components; x = [1.3, 3.7, 0.5] -> [0.5, 1.3, 3.7] and
  2549. -    the permutation is order = [2, 0, 1].
  2550. -    -- if order is NULL on entry then it is ignored
  2551. -    -- the sorted vector x is returned */
  2552. -VEC    *v_sort(x, order)
  2553. -VEC    *x;
  2554. -PERM    *order;
  2555. -{
  2556. -    Real    *x_ve, tmp, v;
  2557. -    /* int        *order_pe; */
  2558. -    int        dim, i, j, l, r, tmp_i;
  2559. -    int        stack[MAX_STACK], sp;
  2560. -
  2561. -    if ( ! x )
  2562. -    error(E_NULL,"v_sort");
  2563. -    if ( order != PNULL && order->size != x->dim )
  2564. -    order = px_resize(order, x->dim);
  2565. -
  2566. -    x_ve = x->ve;
  2567. -    dim = x->dim;
  2568. -    if ( order != PNULL )
  2569. -    px_ident(order);
  2570. -
  2571. -    if ( dim <= 1 )
  2572. -    return x;
  2573. -
  2574. -    /* using quicksort algorithm in Sedgewick,
  2575. -       "Algorithms in C", Ch. 9, pp. 118--122 (1990) */
  2576. -    sp = 0;
  2577. -    l = 0;    r = dim-1;    v = x_ve[0];
  2578. -    for ( ; ; )
  2579. -    {
  2580. -    while ( r > l )
  2581. -    {
  2582. -        /* "i = partition(x_ve,l,r);" */
  2583. -        v = x_ve[r];
  2584. -        i = l-1;
  2585. -        j = r;
  2586. -        for ( ; ; )
  2587. -        {
  2588. -        while ( x_ve[++i] < v )
  2589. -            ;
  2590. -        while ( x_ve[--j] > v )
  2591. -            ;
  2592. -        if ( i >= j )    break;
  2593. -        
  2594. -        tmp = x_ve[i];
  2595. -        x_ve[i] = x_ve[j];
  2596. -        x_ve[j] = tmp;
  2597. -        if ( order != PNULL )
  2598. -        {
  2599. -            tmp_i = order->pe[i];
  2600. -            order->pe[i] = order->pe[j];
  2601. -            order->pe[j] = tmp_i;
  2602. -        }
  2603. -        }
  2604. -        tmp = x_ve[i];
  2605. -        x_ve[i] = x_ve[r];
  2606. -        x_ve[r] = tmp;
  2607. -        if ( order != PNULL )
  2608. -        {
  2609. -        tmp_i = order->pe[i];
  2610. -        order->pe[i] = order->pe[r];
  2611. -        order->pe[r] = tmp_i;
  2612. -        }
  2613. -
  2614. -        if ( i-l > r-i )
  2615. -        {   stack[sp++] = l;   stack[sp++] = i-1;   l = i+1;   }
  2616. -        else
  2617. -        {   stack[sp++] = i+1;   stack[sp++] = r;   r = i-1;   }
  2618. -    }
  2619. -
  2620. -    /* recursion elimination */
  2621. -    if ( sp == 0 )
  2622. -        break;
  2623. -    r = stack[--sp];
  2624. -    l = stack[--sp];
  2625. -    }
  2626. -
  2627. -    return x;
  2628. -}
  2629. -
  2630. -/* v_sum -- returns sum of entries of a vector */
  2631. -double    v_sum(x)
  2632. -VEC    *x;
  2633. -{
  2634. -    int        i;
  2635. -    Real    sum;
  2636. -
  2637. -    if ( ! x )
  2638. -    error(E_NULL,"v_sum");
  2639. -
  2640. -    sum = 0.0;
  2641. -    for ( i = 0; i < x->dim; i++ )
  2642. -    sum += x->ve[i];
  2643. -
  2644. -    return sum;
  2645. -}
  2646. -
  2647. -/* v_conv -- computes convolution product of two vectors */
  2648. -VEC    *v_conv(x1, x2, out)
  2649. -VEC    *x1, *x2, *out;
  2650. -{
  2651. -    int        i;
  2652. -
  2653. -    if ( ! x1 || ! x2 )
  2654. -    error(E_NULL,"v_conv");
  2655. -    if ( x1 == out || x2 == out )
  2656. -    error(E_INSITU,"v_conv");
  2657. -    if ( x1->dim == 0 || x2->dim == 0 )
  2658. -    return out = v_resize(out,0);
  2659. -
  2660. -    out = v_resize(out,x1->dim + x2->dim - 1);
  2661. -    v_zero(out);
  2662. -    for ( i = 0; i < x1->dim; i++ )
  2663. -    __mltadd__(&(out->ve[i]),x2->ve,x1->ve[i],x2->dim);
  2664. -
  2665. -    return out;
  2666. -}
  2667. -
  2668. -/* v_pconv -- computes a periodic convolution product
  2669. -    -- the period is the dimension of x2 */
  2670. -VEC    *v_pconv(x1, x2, out)
  2671. -VEC    *x1, *x2, *out;
  2672. -{
  2673. -    int        i;
  2674. -
  2675. -    if ( ! x1 || ! x2 )
  2676. -    error(E_NULL,"v_pconv");
  2677. -    if ( x1 == out || x2 == out )
  2678. -    error(E_INSITU,"v_pconv");
  2679. -    out = v_resize(out,x2->dim);
  2680. -    if ( x2->dim == 0 )
  2681. -    return out;
  2682. -
  2683. -    v_zero(out);
  2684. -    for ( i = 0; i < x1->dim; i++ )
  2685. -    {
  2686. -    __mltadd__(&(out->ve[i]),x2->ve,x1->ve[i],x2->dim - i);
  2687. -    if ( i > 0 )
  2688. -        __mltadd__(out->ve,&(x2->ve[x2->dim - i]),x1->ve[i],i);
  2689. -    }
  2690. -
  2691. -    return out;
  2692. -}
  2693. //GO.SYSIN DD vecop.c
  2694. echo matop.c 1>&2
  2695. sed >matop.c <<'//GO.SYSIN DD matop.c' 's/^-//'
  2696. -
  2697. -/**************************************************************************
  2698. -**
  2699. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  2700. -**
  2701. -**                 Meschach Library
  2702. -** 
  2703. -** This Meschach Library is provided "as is" without any express 
  2704. -** or implied warranty of any kind with respect to this software. 
  2705. -** In particular the authors shall not be liable for any direct, 
  2706. -** indirect, special, incidental or consequential damages arising 
  2707. -** in any way from use of the software.
  2708. -** 
  2709. -** Everyone is granted permission to copy, modify and redistribute this
  2710. -** Meschach Library, provided:
  2711. -**  1.  All copies contain this copyright notice.
  2712. -**  2.  All modified copies shall carry a notice stating who
  2713. -**      made the last modification and the date of such modification.
  2714. -**  3.  No charge is made for this software or works derived from it.  
  2715. -**      This clause shall not be construed as constraining other software
  2716. -**      distributed on the same medium as this software, nor is a
  2717. -**      distribution fee considered a charge.
  2718. -**
  2719. -***************************************************************************/
  2720. -
  2721. -
  2722. -/* matop.c 1.3 11/25/87 */
  2723. -
  2724. -
  2725. -#include    <stdio.h>
  2726. -#include    "matrix.h"
  2727. -
  2728. -static    char    rcsid[] = "$Id: matop.c,v 1.3 1994/01/13 05:30:28 des Exp $";
  2729. -
  2730. -
  2731. -/* m_add -- matrix addition -- may be in-situ */
  2732. -MAT    *m_add(mat1,mat2,out)
  2733. -MAT    *mat1,*mat2,*out;
  2734. -{
  2735. -    u_int    m,n,i;
  2736. -
  2737. -    if ( mat1==(MAT *)NULL || mat2==(MAT *)NULL )
  2738. -        error(E_NULL,"m_add");
  2739. -    if ( mat1->m != mat2->m || mat1->n != mat2->n )
  2740. -        error(E_SIZES,"m_add");
  2741. -    if ( out==(MAT *)NULL || out->m != mat1->m || out->n != mat1->n )
  2742. -        out = m_resize(out,mat1->m,mat1->n);
  2743. -    m = mat1->m;    n = mat1->n;
  2744. -    for ( i=0; i<m; i++ )
  2745. -    {
  2746. -        __add__(mat1->me[i],mat2->me[i],out->me[i],(int)n);
  2747. -        /**************************************************
  2748. -        for ( j=0; j<n; j++ )
  2749. -            out->me[i][j] = mat1->me[i][j]+mat2->me[i][j];
  2750. -        **************************************************/
  2751. -    }
  2752. -
  2753. -    return (out);
  2754. -}
  2755. -
  2756. -/* m_sub -- matrix subtraction -- may be in-situ */
  2757. -MAT    *m_sub(mat1,mat2,out)
  2758. -MAT    *mat1,*mat2,*out;
  2759. -{
  2760. -    u_int    m,n,i;
  2761. -
  2762. -    if ( mat1==(MAT *)NULL || mat2==(MAT *)NULL )
  2763. -        error(E_NULL,"m_sub");
  2764. -    if ( mat1->m != mat2->m || mat1->n != mat2->n )
  2765. -        error(E_SIZES,"m_sub");
  2766. -    if ( out==(MAT *)NULL || out->m != mat1->m || out->n != mat1->n )
  2767. -        out = m_resize(out,mat1->m,mat1->n);
  2768. -    m = mat1->m;    n = mat1->n;
  2769. -    for ( i=0; i<m; i++ )
  2770. -    {
  2771. -        __sub__(mat1->me[i],mat2->me[i],out->me[i],(int)n);
  2772. -        /**************************************************
  2773. -        for ( j=0; j<n; j++ )
  2774. -            out->me[i][j] = mat1->me[i][j]-mat2->me[i][j];
  2775. -        **************************************************/
  2776. -    }
  2777. -
  2778. -    return (out);
  2779. -}
  2780. -
  2781. -/* m_mlt -- matrix-matrix multiplication */
  2782. -MAT    *m_mlt(A,B,OUT)
  2783. -MAT    *A,*B,*OUT;
  2784. -{
  2785. -    u_int    i, /* j, */ k, m, n, p;
  2786. -    Real    **A_v, **B_v /*, *B_row, *OUT_row, sum, tmp */;
  2787. -
  2788. -    if ( A==(MAT *)NULL || B==(MAT *)NULL )
  2789. -        error(E_NULL,"m_mlt");
  2790. -    if ( A->n != B->m )
  2791. -        error(E_SIZES,"m_mlt");
  2792. -    if ( A == OUT || B == OUT )
  2793. -        error(E_INSITU,"m_mlt");
  2794. -    m = A->m;    n = A->n;    p = B->n;
  2795. -    A_v = A->me;        B_v = B->me;
  2796. -
  2797. -    if ( OUT==(MAT *)NULL || OUT->m != A->m || OUT->n != B->n )
  2798. -        OUT = m_resize(OUT,A->m,B->n);
  2799. -
  2800. -/****************************************************************
  2801. -    for ( i=0; i<m; i++ )
  2802. -        for  ( j=0; j<p; j++ )
  2803. -        {
  2804. -            sum = 0.0;
  2805. -            for ( k=0; k<n; k++ )
  2806. -                sum += A_v[i][k]*B_v[k][j];
  2807. -            OUT->me[i][j] = sum;
  2808. -        }
  2809. -****************************************************************/
  2810. -    m_zero(OUT);
  2811. -    for ( i=0; i<m; i++ )
  2812. -        for ( k=0; k<n; k++ )
  2813. -        {
  2814. -            if ( A_v[i][k] != 0.0 )
  2815. -                __mltadd__(OUT->me[i],B_v[k],A_v[i][k],(int)p);
  2816. -            /**************************************************
  2817. -            B_row = B_v[k];    OUT_row = OUT->me[i];
  2818. -            for ( j=0; j<p; j++ )
  2819. -            (*OUT_row++) += tmp*(*B_row++);
  2820. -            **************************************************/
  2821. -        }
  2822. -
  2823. -    return OUT;
  2824. -}
  2825. -
  2826. -/* mmtr_mlt -- matrix-matrix transposed multiplication
  2827. -    -- A.B^T is returned, and stored in OUT */
  2828. -MAT    *mmtr_mlt(A,B,OUT)
  2829. -MAT    *A, *B, *OUT;
  2830. -{
  2831. -    int    i, j, limit;
  2832. -    /* Real    *A_row, *B_row, sum; */
  2833. -
  2834. -    if ( ! A || ! B )
  2835. -        error(E_NULL,"mmtr_mlt");
  2836. -    if ( A == OUT || B == OUT )
  2837. -        error(E_INSITU,"mmtr_mlt");
  2838. -    if ( A->n != B->n )
  2839. -        error(E_SIZES,"mmtr_mlt");
  2840. -    if ( ! OUT || OUT->m != A->m || OUT->n != B->m )
  2841. -        OUT = m_resize(OUT,A->m,B->m);
  2842. -
  2843. -    limit = A->n;
  2844. -    for ( i = 0; i < A->m; i++ )
  2845. -        for ( j = 0; j < B->m; j++ )
  2846. -        {
  2847. -            OUT->me[i][j] = __ip__(A->me[i],B->me[j],(int)limit);
  2848. -            /**************************************************
  2849. -            sum = 0.0;
  2850. -            A_row = A->me[i];
  2851. -            B_row = B->me[j];
  2852. -            for ( k = 0; k < limit; k++ )
  2853. -            sum += (*A_row++)*(*B_row++);
  2854. -            OUT->me[i][j] = sum;
  2855. -            **************************************************/
  2856. -        }
  2857. -
  2858. -    return OUT;
  2859. -}
  2860. -
  2861. -/* mtrm_mlt -- matrix transposed-matrix multiplication
  2862. -    -- A^T.B is returned, result stored in OUT */
  2863. -MAT    *mtrm_mlt(A,B,OUT)
  2864. -MAT    *A, *B, *OUT;
  2865. -{
  2866. -    int    i, k, limit;
  2867. -    /* Real    *B_row, *OUT_row, multiplier; */
  2868. -
  2869. -    if ( ! A || ! B )
  2870. -        error(E_NULL,"mmtr_mlt");
  2871. -    if ( A == OUT || B == OUT )
  2872. -        error(E_INSITU,"mtrm_mlt");
  2873. -    if ( A->m != B->m )
  2874. -        error(E_SIZES,"mmtr_mlt");
  2875. -    if ( ! OUT || OUT->m != A->n || OUT->n != B->n )
  2876. -        OUT = m_resize(OUT,A->n,B->n);
  2877. -
  2878. -    limit = B->n;
  2879. -    m_zero(OUT);
  2880. -    for ( k = 0; k < A->m; k++ )
  2881. -        for ( i = 0; i < A->n; i++ )
  2882. -        {
  2883. -            if ( A->me[k][i] != 0.0 )
  2884. -            __mltadd__(OUT->me[i],B->me[k],A->me[k][i],(int)limit);
  2885. -            /**************************************************
  2886. -            multiplier = A->me[k][i];
  2887. -            OUT_row = OUT->me[i];
  2888. -            B_row   = B->me[k];
  2889. -            for ( j = 0; j < limit; j++ )
  2890. -            *(OUT_row++) += multiplier*(*B_row++);
  2891. -            **************************************************/
  2892. -        }
  2893. -
  2894. -    return OUT;
  2895. -}
  2896. -
  2897. -/* mv_mlt -- matrix-vector multiplication 
  2898. -        -- Note: b is treated as a column vector */
  2899. -VEC    *mv_mlt(A,b,out)
  2900. -MAT    *A;
  2901. -VEC    *b,*out;
  2902. -{
  2903. -    u_int    i, m, n;
  2904. -    Real    **A_v, *b_v /*, *A_row */;
  2905. -    /* register Real    sum; */
  2906. -
  2907. -    if ( A==(MAT *)NULL || b==(VEC *)NULL )
  2908. -        error(E_NULL,"mv_mlt");
  2909. -    if ( A->n != b->dim )
  2910. -        error(E_SIZES,"mv_mlt");
  2911. -    if ( b == out )
  2912. -        error(E_INSITU,"mv_mlt");
  2913. -    if ( out == (VEC *)NULL || out->dim != A->m )
  2914. -        out = v_resize(out,A->m);
  2915. -
  2916. -    m = A->m;        n = A->n;
  2917. -    A_v = A->me;        b_v = b->ve;
  2918. -    for ( i=0; i<m; i++ )
  2919. -    {
  2920. -        /* for ( j=0; j<n; j++ )
  2921. -            sum += A_v[i][j]*b_v[j]; */
  2922. -        out->ve[i] = __ip__(A_v[i],b_v,(int)n);
  2923. -        /**************************************************
  2924. -        A_row = A_v[i];        b_v = b->ve;
  2925. -        for ( j=0; j<n; j++ )
  2926. -            sum += (*A_row++)*(*b_v++);
  2927. -        out->ve[i] = sum;
  2928. -        **************************************************/
  2929. -    }
  2930. -
  2931. -    return out;
  2932. -}
  2933. -
  2934. -/* sm_mlt -- scalar-matrix multiply -- may be in-situ */
  2935. -MAT    *sm_mlt(scalar,matrix,out)
  2936. -double    scalar;
  2937. -MAT    *matrix,*out;
  2938. -{
  2939. -    u_int    m,n,i;
  2940. -
  2941. -    if ( matrix==(MAT *)NULL )
  2942. -        error(E_NULL,"sm_mlt");
  2943. -    if ( out==(MAT *)NULL || out->m != matrix->m || out->n != matrix->n )
  2944. -        out = m_resize(out,matrix->m,matrix->n);
  2945. -    m = matrix->m;    n = matrix->n;
  2946. -    for ( i=0; i<m; i++ )
  2947. -        __smlt__(matrix->me[i],(double)scalar,out->me[i],(int)n);
  2948. -        /**************************************************
  2949. -        for ( j=0; j<n; j++ )
  2950. -            out->me[i][j] = scalar*matrix->me[i][j];
  2951. -        **************************************************/
  2952. -    return (out);
  2953. -}
  2954. -
  2955. -/* vm_mlt -- vector-matrix multiplication 
  2956. -        -- Note: b is treated as a row vector */
  2957. -VEC    *vm_mlt(A,b,out)
  2958. -MAT    *A;
  2959. -VEC    *b,*out;
  2960. -{
  2961. -    u_int    j,m,n;
  2962. -    /* Real    sum,**A_v,*b_v; */
  2963. -
  2964. -    if ( A==(MAT *)NULL || b==(VEC *)NULL )
  2965. -        error(E_NULL,"vm_mlt");
  2966. -    if ( A->m != b->dim )
  2967. -        error(E_SIZES,"vm_mlt");
  2968. -    if ( b == out )
  2969. -        error(E_INSITU,"vm_mlt");
  2970. -    if ( out == (VEC *)NULL || out->dim != A->n )
  2971. -        out = v_resize(out,A->n);
  2972. -
  2973. -    m = A->m;        n = A->n;
  2974. -
  2975. -    v_zero(out);
  2976. -    for ( j = 0; j < m; j++ )
  2977. -        if ( b->ve[j] != 0.0 )
  2978. -            __mltadd__(out->ve,A->me[j],b->ve[j],(int)n);
  2979. -    /**************************************************
  2980. -    A_v = A->me;        b_v = b->ve;
  2981. -    for ( j=0; j<n; j++ )
  2982. -    {
  2983. -        sum = 0.0;
  2984. -        for ( i=0; i<m; i++ )
  2985. -            sum += b_v[i]*A_v[i][j];
  2986. -        out->ve[j] = sum;
  2987. -    }
  2988. -    **************************************************/
  2989. -
  2990. -    return out;
  2991. -}
  2992. -
  2993. -/* m_transp -- transpose matrix */
  2994. -MAT    *m_transp(in,out)
  2995. -MAT    *in, *out;
  2996. -{
  2997. -    int    i, j;
  2998. -    int    in_situ;
  2999. -    Real    tmp;
  3000. -
  3001. -    if ( in == (MAT *)NULL )
  3002. -        error(E_NULL,"m_transp");
  3003. -    if ( in == out && in->n != in->m )
  3004. -        error(E_INSITU2,"m_transp");
  3005. -    in_situ = ( in == out );
  3006. -    if ( out == (MAT *)NULL || out->m != in->n || out->n != in->m )
  3007. -        out = m_resize(out,in->n,in->m);
  3008. -
  3009. -    if ( ! in_situ )
  3010. -        for ( i = 0; i < in->m; i++ )
  3011. -            for ( j = 0; j < in->n; j++ )
  3012. -                out->me[j][i] = in->me[i][j];
  3013. -    else
  3014. -        for ( i = 1; i < in->m; i++ )
  3015. -            for ( j = 0; j < i; j++ )
  3016. -            {    tmp = in->me[i][j];
  3017. -                in->me[i][j] = in->me[j][i];
  3018. -                in->me[j][i] = tmp;
  3019. -            }
  3020. -
  3021. -    return out;
  3022. -}
  3023. -
  3024. -/* swap_rows -- swaps rows i and j of matrix A upto column lim */
  3025. -MAT    *swap_rows(A,i,j,lo,hi)
  3026. -MAT    *A;
  3027. -int    i, j, lo, hi;
  3028. -{
  3029. -    int    k;
  3030. -    Real    **A_me, tmp;
  3031. -
  3032. -    if ( ! A )
  3033. -        error(E_NULL,"swap_rows");
  3034. -    if ( i < 0 || j < 0 || i >= A->m || j >= A->m )
  3035. -        error(E_SIZES,"swap_rows");
  3036. -    lo = max(0,lo);
  3037. -    hi = min(hi,A->n-1);
  3038. -    A_me = A->me;
  3039. -
  3040. -    for ( k = lo; k <= hi; k++ )
  3041. -    {
  3042. -        tmp = A_me[k][i];
  3043. -        A_me[k][i] = A_me[k][j];
  3044. -        A_me[k][j] = tmp;
  3045. -    }
  3046. -    return A;
  3047. -}
  3048. -
  3049. -/* swap_cols -- swap columns i and j of matrix A upto row lim */
  3050. -MAT    *swap_cols(A,i,j,lo,hi)
  3051. -MAT    *A;
  3052. -int    i, j, lo, hi;
  3053. -{
  3054. -    int    k;
  3055. -    Real    **A_me, tmp;
  3056. -
  3057. -    if ( ! A )
  3058. -        error(E_NULL,"swap_cols");
  3059. -    if ( i < 0 || j < 0 || i >= A->n || j >= A->n )
  3060. -        error(E_SIZES,"swap_cols");
  3061. -    lo = max(0,lo);
  3062. -    hi = min(hi,A->m-1);
  3063. -    A_me = A->me;
  3064. -
  3065. -    for ( k = lo; k <= hi; k++ )
  3066. -    {
  3067. -        tmp = A_me[i][k];
  3068. -        A_me[i][k] = A_me[j][k];
  3069. -        A_me[j][k] = tmp;
  3070. -    }
  3071. -    return A;
  3072. -}
  3073. -
  3074. -/* ms_mltadd -- matrix-scalar multiply and add
  3075. -    -- may be in situ
  3076. -    -- returns out == A1 + s*A2 */
  3077. -MAT    *ms_mltadd(A1,A2,s,out)
  3078. -MAT    *A1, *A2, *out;
  3079. -double    s;
  3080. -{
  3081. -    /* register Real    *A1_e, *A2_e, *out_e; */
  3082. -    /* register int    j; */
  3083. -    int    i, m, n;
  3084. -
  3085. -    if ( ! A1 || ! A2 )
  3086. -        error(E_NULL,"ms_mltadd");
  3087. -    if ( A1->m != A2->m || A1->n != A2->n )
  3088. -        error(E_SIZES,"ms_mltadd");
  3089. -
  3090. -    if ( s == 0.0 )
  3091. -        return m_copy(A1,out);
  3092. -    if ( s == 1.0 )
  3093. -        return m_add(A1,A2,out);
  3094. -
  3095. -    tracecatch(out = m_copy(A1,out),"ms_mltadd");
  3096. -
  3097. -    m = A1->m;    n = A1->n;
  3098. -    for ( i = 0; i < m; i++ )
  3099. -    {
  3100. -        __mltadd__(out->me[i],A2->me[i],s,(int)n);
  3101. -        /**************************************************
  3102. -        A1_e = A1->me[i];
  3103. -        A2_e = A2->me[i];
  3104. -        out_e = out->me[i];
  3105. -        for ( j = 0; j < n; j++ )
  3106. -            out_e[j] = A1_e[j] + s*A2_e[j];
  3107. -        **************************************************/
  3108. -    }
  3109. -
  3110. -    return out;
  3111. -}
  3112. -
  3113. -/* mv_mltadd -- matrix-vector multiply and add
  3114. -    -- may not be in situ
  3115. -    -- returns out == v1 + alpha*A*v2 */
  3116. -VEC    *mv_mltadd(v1,v2,A,alpha,out)
  3117. -VEC    *v1, *v2, *out;
  3118. -MAT    *A;
  3119. -double    alpha;
  3120. -{
  3121. -    /* register    int    j; */
  3122. -    int    i, m, n;
  3123. -    Real    *v2_ve, *out_ve;
  3124. -
  3125. -    if ( ! v1 || ! v2 || ! A )
  3126. -        error(E_NULL,"mv_mltadd");
  3127. -    if ( out == v2 )
  3128. -        error(E_INSITU,"mv_mltadd");
  3129. -    if ( v1->dim != A->m || v2->dim != A-> n )
  3130. -        error(E_SIZES,"mv_mltadd");
  3131. -
  3132. -    tracecatch(out = v_copy(v1,out),"mv_mltadd");
  3133. -
  3134. -    v2_ve = v2->ve;    out_ve = out->ve;
  3135. -    m = A->m;    n = A->n;
  3136. -
  3137. -    if ( alpha == 0.0 )
  3138. -        return out;
  3139. -
  3140. -    for ( i = 0; i < m; i++ )
  3141. -    {
  3142. -        out_ve[i] += alpha*__ip__(A->me[i],v2_ve,(int)n);
  3143. -        /**************************************************
  3144. -        A_e = A->me[i];
  3145. -        sum = 0.0;
  3146. -        for ( j = 0; j < n; j++ )
  3147. -            sum += A_e[j]*v2_ve[j];
  3148. -        out_ve[i] = v1->ve[i] + alpha*sum;
  3149. -        **************************************************/
  3150. -    }
  3151. -
  3152. -    return out;
  3153. -}
  3154. -
  3155. -/* vm_mltadd -- vector-matrix multiply and add
  3156. -    -- may not be in situ
  3157. -    -- returns out' == v1' + v2'*A */
  3158. -VEC    *vm_mltadd(v1,v2,A,alpha,out)
  3159. -VEC    *v1, *v2, *out;
  3160. -MAT    *A;
  3161. -double    alpha;
  3162. -{
  3163. -    int    /* i, */ j, m, n;
  3164. -    Real    tmp, /* *A_e, */ *out_ve;
  3165. -
  3166. -    if ( ! v1 || ! v2 || ! A )
  3167. -        error(E_NULL,"vm_mltadd");
  3168. -    if ( v2 == out )
  3169. -        error(E_INSITU,"vm_mltadd");
  3170. -    if ( v1->dim != A->n || A->m != v2->dim )
  3171. -        error(E_SIZES,"vm_mltadd");
  3172. -
  3173. -    tracecatch(out = v_copy(v1,out),"vm_mltadd");
  3174. -
  3175. -    out_ve = out->ve;    m = A->m;    n = A->n;
  3176. -    for ( j = 0; j < m; j++ )
  3177. -    {
  3178. -        tmp = v2->ve[j]*alpha;
  3179. -        if ( tmp != 0.0 )
  3180. -            __mltadd__(out_ve,A->me[j],tmp,(int)n);
  3181. -        /**************************************************
  3182. -        A_e = A->me[j];
  3183. -        for ( i = 0; i < n; i++ )
  3184. -            out_ve[i] += A_e[i]*tmp;
  3185. -        **************************************************/
  3186. -    }
  3187. -
  3188. -    return out;
  3189. -}
  3190. -
  3191. //GO.SYSIN DD matop.c
  3192. echo pxop.c 1>&2
  3193. sed >pxop.c <<'//GO.SYSIN DD pxop.c' 's/^-//'
  3194. -
  3195. -/**************************************************************************
  3196. -**
  3197. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  3198. -**
  3199. -**                 Meschach Library
  3200. -** 
  3201. -** This Meschach Library is provided "as is" without any express 
  3202. -** or implied warranty of any kind with respect to this software. 
  3203. -** In particular the authors shall not be liable for any direct, 
  3204. -** indirect, special, incidental or consequential damages arising 
  3205. -** in any way from use of the software.
  3206. -** 
  3207. -** Everyone is granted permission to copy, modify and redistribute this
  3208. -** Meschach Library, provided:
  3209. -**  1.  All copies contain this copyright notice.
  3210. -**  2.  All modified copies shall carry a notice stating who
  3211. -**      made the last modification and the date of such modification.
  3212. -**  3.  No charge is made for this software or works derived from it.  
  3213. -**      This clause shall not be construed as constraining other software
  3214. -**      distributed on the same medium as this software, nor is a
  3215. -**      distribution fee considered a charge.
  3216. -**
  3217. -***************************************************************************/
  3218. -
  3219. -
  3220. -/* pxop.c 1.5 12/03/87 */
  3221. -
  3222. -
  3223. -#include    <stdio.h>
  3224. -#include    "matrix.h"
  3225. -
  3226. -static    char    rcsid[] = "$Id: pxop.c,v 1.5 1994/03/23 23:58:50 des Exp $";
  3227. -
  3228. -/**********************************************************************
  3229. -Note: A permutation is often interpreted as a matrix
  3230. -        (i.e. a permutation matrix).
  3231. -    A permutation px represents a permutation matrix P where
  3232. -        P[i][j] == 1 if and only if px->pe[i] == j
  3233. -**********************************************************************/
  3234. -
  3235. -
  3236. -/* px_inv -- invert permutation -- in situ
  3237. -    -- taken from ACM Collected Algorithms #250 */
  3238. -PERM    *px_inv(px,out)
  3239. -PERM    *px, *out;
  3240. -{
  3241. -    int    i, j, k, n, *p;
  3242. -    
  3243. -    out = px_copy(px, out);
  3244. -    n = out->size;
  3245. -    p = (int *)(out->pe);
  3246. -    for ( n--; n>=0; n-- )
  3247. -    {
  3248. -    i = p[n];
  3249. -    if ( i < 0 )    p[n] = -1 - i;
  3250. -    else if ( i != n )
  3251. -    {
  3252. -        k = n;
  3253. -        while (TRUE)
  3254. -        {
  3255. -        if ( i < 0 || i >= out->size )
  3256. -            error(E_BOUNDS,"px_inv");
  3257. -        j = p[i];    p[i] = -1 - k;
  3258. -        if ( j == n )
  3259. -        {    p[n] = i;    break;        }
  3260. -        k = i;        i = j;
  3261. -        }
  3262. -    }
  3263. -    }
  3264. -    return out;
  3265. -}
  3266. -
  3267. -/* px_mlt -- permutation multiplication (composition) */
  3268. -PERM    *px_mlt(px1,px2,out)
  3269. -PERM    *px1,*px2,*out;
  3270. -{
  3271. -    u_int    i,size;
  3272. -    
  3273. -    if ( px1==(PERM *)NULL || px2==(PERM *)NULL )
  3274. -    error(E_NULL,"px_mlt");
  3275. -    if ( px1->size != px2->size )
  3276. -    error(E_SIZES,"px_mlt");
  3277. -    if ( px1 == out || px2 == out )
  3278. -    error(E_INSITU,"px_mlt");
  3279. -    if ( out==(PERM *)NULL || out->size < px1->size )
  3280. -    out = px_resize(out,px1->size);
  3281. -    
  3282. -    size = px1->size;
  3283. -    for ( i=0; i<size; i++ )
  3284. -    if ( px2->pe[i] >= size )
  3285. -        error(E_BOUNDS,"px_mlt");
  3286. -    else
  3287. -        out->pe[i] = px1->pe[px2->pe[i]];
  3288. -    
  3289. -    return out;
  3290. -}
  3291. -
  3292. -/* px_vec -- permute vector */
  3293. -VEC    *px_vec(px,vector,out)
  3294. -PERM    *px;
  3295. -VEC    *vector,*out;
  3296. -{
  3297. -    u_int    old_i, i, size, start;
  3298. -    Real    tmp;
  3299. -    
  3300. -    if ( px==(PERM *)NULL || vector==(VEC *)NULL )
  3301. -    error(E_NULL,"px_vec");
  3302. -    if ( px->size > vector->dim )
  3303. -    error(E_SIZES,"px_vec");
  3304. -    if ( out==(VEC *)NULL || out->dim < vector->dim )
  3305. -    out = v_resize(out,vector->dim);
  3306. -    
  3307. -    size = px->size;
  3308. -    if ( size == 0 )
  3309. -    return v_copy(vector,out);
  3310. -    if ( out != vector )
  3311. -    {
  3312. -    for ( i=0; i<size; i++ )
  3313. -        if ( px->pe[i] >= size )
  3314. -        error(E_BOUNDS,"px_vec");
  3315. -        else
  3316. -        out->ve[i] = vector->ve[px->pe[i]];
  3317. -    }
  3318. -    else
  3319. -    {    /* in situ algorithm */
  3320. -    start = 0;
  3321. -    while ( start < size )
  3322. -    {
  3323. -        old_i = start;
  3324. -        i = px->pe[old_i];
  3325. -        if ( i >= size )
  3326. -        {
  3327. -        start++;
  3328. -        continue;
  3329. -        }
  3330. -        tmp = vector->ve[start];
  3331. -        while ( TRUE )
  3332. -        {
  3333. -        vector->ve[old_i] = vector->ve[i];
  3334. -        px->pe[old_i] = i+size;
  3335. -        old_i = i;
  3336. -        i = px->pe[old_i];
  3337. -        if ( i >= size )
  3338. -            break;
  3339. -        if ( i == start )
  3340. -        {
  3341. -            vector->ve[old_i] = tmp;
  3342. -            px->pe[old_i] = i+size;
  3343. -            break;
  3344. -        }
  3345. -        }
  3346. -        start++;
  3347. -    }
  3348. -
  3349. -    for ( i = 0; i < size; i++ )
  3350. -        if ( px->pe[i] < size )
  3351. -        error(E_BOUNDS,"px_vec");
  3352. -        else
  3353. -        px->pe[i] = px->pe[i]-size;
  3354. -    }
  3355. -    
  3356. -    return out;
  3357. -}
  3358. -
  3359. -/* pxinv_vec -- apply the inverse of px to x, returning the result in out */
  3360. -VEC    *pxinv_vec(px,x,out)
  3361. -PERM    *px;
  3362. -VEC    *x, *out;
  3363. -{
  3364. -    u_int    i, size;
  3365. -    
  3366. -    if ( ! px || ! x )
  3367. -    error(E_NULL,"pxinv_vec");
  3368. -    if ( px->size > x->dim )
  3369. -    error(E_SIZES,"pxinv_vec");
  3370. -    /* if ( x == out )
  3371. -    error(E_INSITU,"pxinv_vec"); */
  3372. -    if ( ! out || out->dim < x->dim )
  3373. -    out = v_resize(out,x->dim);
  3374. -    
  3375. -    size = px->size;
  3376. -    if ( size == 0 )
  3377. -    return v_copy(x,out);
  3378. -    if ( out != x )
  3379. -    {
  3380. -    for ( i=0; i<size; i++ )
  3381. -        if ( px->pe[i] >= size )
  3382. -        error(E_BOUNDS,"pxinv_vec");
  3383. -        else
  3384. -        out->ve[px->pe[i]] = x->ve[i];
  3385. -    }
  3386. -    else
  3387. -    {    /* in situ algorithm --- cheat's way out */
  3388. -    px_inv(px,px);
  3389. -    px_vec(px,x,out);
  3390. -    px_inv(px,px);
  3391. -    }
  3392. -
  3393. -    return out;
  3394. -}
  3395. -
  3396. -
  3397. -
  3398. -/* px_transp -- transpose elements of permutation
  3399. -        -- Really multiplying a permutation by a transposition */
  3400. -PERM    *px_transp(px,i1,i2)
  3401. -PERM    *px;        /* permutation to transpose */
  3402. -u_int    i1,i2;        /* elements to transpose */
  3403. -{
  3404. -    u_int    temp;
  3405. -
  3406. -    if ( px==(PERM *)NULL )
  3407. -        error(E_NULL,"px_transp");
  3408. -
  3409. -    if ( i1 < px->size && i2 < px->size )
  3410. -    {
  3411. -        temp = px->pe[i1];
  3412. -        px->pe[i1] = px->pe[i2];
  3413. -        px->pe[i2] = temp;
  3414. -    }
  3415. -
  3416. -    return px;
  3417. -}
  3418. -
  3419. -/* myqsort -- a cheap implementation of Quicksort on integers
  3420. -        -- returns number of swaps */
  3421. -static int myqsort(a,num)
  3422. -int    *a, num;
  3423. -{
  3424. -    int    i, j, tmp, v;
  3425. -    int    numswaps;
  3426. -
  3427. -    numswaps = 0;
  3428. -    if ( num <= 1 )
  3429. -        return 0;
  3430. -
  3431. -    i = 0;    j = num;    v = a[0];
  3432. -    for ( ; ; )
  3433. -    {
  3434. -        while ( a[++i] < v )
  3435. -            ;
  3436. -        while ( a[--j] > v )
  3437. -            ;
  3438. -        if ( i >= j )    break;
  3439. -
  3440. -        tmp = a[i];
  3441. -        a[i] = a[j];
  3442. -        a[j] = tmp;
  3443. -        numswaps++;
  3444. -    }
  3445. -
  3446. -    tmp = a[0];
  3447. -    a[0] = a[j];
  3448. -    a[j] = tmp;
  3449. -    if ( j != 0 )
  3450. -        numswaps++;
  3451. -
  3452. -    numswaps += myqsort(&a[0],j);
  3453. -    numswaps += myqsort(&a[j+1],num-(j+1));
  3454. -
  3455. -    return numswaps;
  3456. -}
  3457. -
  3458. -
  3459. -/* px_sign -- compute the ``sign'' of a permutation = +/-1 where
  3460. -        px is the product of an even/odd # transpositions */
  3461. -int    px_sign(px)
  3462. -PERM    *px;
  3463. -{
  3464. -    int    numtransp;
  3465. -    PERM    *px2;
  3466. -
  3467. -    if ( px==(PERM *)NULL )
  3468. -        error(E_NULL,"px_sign");
  3469. -    px2 = px_copy(px,PNULL);
  3470. -    numtransp = myqsort(px2->pe,px2->size);
  3471. -    px_free(px2);
  3472. -
  3473. -    return ( numtransp % 2 ) ? -1 : 1;
  3474. -}
  3475. -
  3476. -
  3477. -/* px_cols -- permute columns of matrix A; out = A.px'
  3478. -    -- May NOT be in situ */
  3479. -MAT    *px_cols(px,A,out)
  3480. -PERM    *px;
  3481. -MAT    *A, *out;
  3482. -{
  3483. -    int    i, j, m, n, px_j;
  3484. -    Real    **A_me, **out_me;
  3485. -#ifdef ANSI_C
  3486. -    MAT    *m_get(int, int);
  3487. -#else
  3488. -    extern MAT    *m_get();
  3489. -#endif
  3490. -
  3491. -    if ( ! A || ! px )
  3492. -        error(E_NULL,"px_cols");
  3493. -    if ( px->size != A->n )
  3494. -        error(E_SIZES,"px_cols");
  3495. -    if ( A == out )
  3496. -        error(E_INSITU,"px_cols");
  3497. -    m = A->m;    n = A->n;
  3498. -    if ( ! out || out->m != m || out->n != n )
  3499. -        out = m_get(m,n);
  3500. -    A_me = A->me;    out_me = out->me;
  3501. -
  3502. -    for ( j = 0; j < n; j++ )
  3503. -    {
  3504. -        px_j = px->pe[j];
  3505. -        if ( px_j >= n )
  3506. -            error(E_BOUNDS,"px_cols");
  3507. -        for ( i = 0; i < m; i++ )
  3508. -            out_me[i][px_j] = A_me[i][j];
  3509. -    }
  3510. -
  3511. -    return out;
  3512. -}
  3513. -
  3514. -/* px_rows -- permute columns of matrix A; out = px.A
  3515. -    -- May NOT be in situ */
  3516. -MAT    *px_rows(px,A,out)
  3517. -PERM    *px;
  3518. -MAT    *A, *out;
  3519. -{
  3520. -    int    i, j, m, n, px_i;
  3521. -    Real    **A_me, **out_me;
  3522. -#ifdef ANSI_C
  3523. -    MAT    *m_get(int, int);
  3524. -#else
  3525. -    extern MAT    *m_get();
  3526. -#endif
  3527. -
  3528. -    if ( ! A || ! px )
  3529. -        error(E_NULL,"px_rows");
  3530. -    if ( px->size != A->m )
  3531. -        error(E_SIZES,"px_rows");
  3532. -    if ( A == out )
  3533. -        error(E_INSITU,"px_rows");
  3534. -    m = A->m;    n = A->n;
  3535. -    if ( ! out || out->m != m || out->n != n )
  3536. -        out = m_get(m,n);
  3537. -    A_me = A->me;    out_me = out->me;
  3538. -
  3539. -    for ( i = 0; i < m; i++ )
  3540. -    {
  3541. -        px_i = px->pe[i];
  3542. -        if ( px_i >= m )
  3543. -            error(E_BOUNDS,"px_rows");
  3544. -        for ( j = 0; j < n; j++ )
  3545. -            out_me[i][j] = A_me[px_i][j];
  3546. -    }
  3547. -
  3548. -    return out;
  3549. -}
  3550. -
  3551. //GO.SYSIN DD pxop.c
  3552. echo submat.c 1>&2
  3553. sed >submat.c <<'//GO.SYSIN DD submat.c' 's/^-//'
  3554. -
  3555. -/**************************************************************************
  3556. -**
  3557. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  3558. -**
  3559. -**                 Meschach Library
  3560. -** 
  3561. -** This Meschach Library is provided "as is" without any express 
  3562. -** or implied warranty of any kind with respect to this software. 
  3563. -** In particular the authors shall not be liable for any direct, 
  3564. -** indirect, special, incidental or consequential damages arising 
  3565. -** in any way from use of the software.
  3566. -** 
  3567. -** Everyone is granted permission to copy, modify and redistribute this
  3568. -** Meschach Library, provided:
  3569. -**  1.  All copies contain this copyright notice.
  3570. -**  2.  All modified copies shall carry a notice stating who
  3571. -**      made the last modification and the date of such modification.
  3572. -**  3.  No charge is made for this software or works derived from it.  
  3573. -**      This clause shall not be construed as constraining other software
  3574. -**      distributed on the same medium as this software, nor is a
  3575. -**      distribution fee considered a charge.
  3576. -**
  3577. -***************************************************************************/
  3578. -
  3579. -
  3580. -/* 1.2 submat.c 11/25/87 */
  3581. -
  3582. -#include    <stdio.h>
  3583. -#include    "matrix.h"
  3584. -
  3585. -static    char    rcsid[] = "$Id: submat.c,v 1.2 1994/01/13 05:28:12 des Exp $";
  3586. -
  3587. -
  3588. -/* get_col -- gets a specified column of a matrix and retruns it as a vector */
  3589. -VEC    *get_col(mat,col,vec)
  3590. -u_int    col;
  3591. -MAT    *mat;
  3592. -VEC    *vec;
  3593. -{
  3594. -   u_int    i;
  3595. -   
  3596. -   if ( mat==(MAT *)NULL )
  3597. -     error(E_NULL,"get_col");
  3598. -   if ( col >= mat->n )
  3599. -     error(E_RANGE,"get_col");
  3600. -   if ( vec==(VEC *)NULL || vec->dim<mat->m )
  3601. -     vec = v_resize(vec,mat->m);
  3602. -   
  3603. -   for ( i=0; i<mat->m; i++ )
  3604. -     vec->ve[i] = mat->me[i][col];
  3605. -   
  3606. -   return (vec);
  3607. -}
  3608. -
  3609. -/* get_row -- gets a specified row of a matrix and retruns it as a vector */
  3610. -VEC    *get_row(mat,row,vec)
  3611. -u_int    row;
  3612. -MAT    *mat;
  3613. -VEC    *vec;
  3614. -{
  3615. -   u_int    i;
  3616. -   
  3617. -   if ( mat==(MAT *)NULL )
  3618. -     error(E_NULL,"get_row");
  3619. -   if ( row >= mat->m )
  3620. -     error(E_RANGE,"get_row");
  3621. -   if ( vec==(VEC *)NULL || vec->dim<mat->n )
  3622. -     vec = v_resize(vec,mat->n);
  3623. -   
  3624. -   for ( i=0; i<mat->n; i++ )
  3625. -     vec->ve[i] = mat->me[row][i];
  3626. -   
  3627. -   return (vec);
  3628. -}
  3629. -
  3630. -/* _set_col -- sets column of matrix to values given in vec (in situ) */
  3631. -MAT    *_set_col(mat,col,vec,i0)
  3632. -MAT    *mat;
  3633. -VEC    *vec;
  3634. -u_int    col,i0;
  3635. -{
  3636. -   u_int    i,lim;
  3637. -   
  3638. -   if ( mat==(MAT *)NULL || vec==(VEC *)NULL )
  3639. -     error(E_NULL,"_set_col");
  3640. -   if ( col >= mat->n )
  3641. -     error(E_RANGE,"_set_col");
  3642. -   lim = min(mat->m,vec->dim);
  3643. -   for ( i=i0; i<lim; i++ )
  3644. -     mat->me[i][col] = vec->ve[i];
  3645. -   
  3646. -   return (mat);
  3647. -}
  3648. -
  3649. -/* _set_row -- sets row of matrix to values given in vec (in situ) */
  3650. -MAT    *_set_row(mat,row,vec,j0)
  3651. -MAT    *mat;
  3652. -VEC    *vec;
  3653. -u_int    row,j0;
  3654. -{
  3655. -   u_int    j,lim;
  3656. -   
  3657. -   if ( mat==(MAT *)NULL || vec==(VEC *)NULL )
  3658. -     error(E_NULL,"_set_row");
  3659. -   if ( row >= mat->m )
  3660. -     error(E_RANGE,"_set_row");
  3661. -   lim = min(mat->n,vec->dim);
  3662. -   for ( j=j0; j<lim; j++ )
  3663. -     mat->me[row][j] = vec->ve[j];
  3664. -   
  3665. -   return (mat);
  3666. -}
  3667. -
  3668. -/* sub_mat -- returns sub-matrix of old which is formed by the rectangle
  3669. -   from (row1,col1) to (row2,col2)
  3670. -   -- Note: storage is shared so that altering the "new"
  3671. -   matrix will alter the "old" matrix */
  3672. -MAT    *sub_mat(old,row1,col1,row2,col2,new)
  3673. -MAT    *old,*new;
  3674. -u_int    row1,col1,row2,col2;
  3675. -{
  3676. -   u_int    i;
  3677. -   
  3678. -   if ( old==(MAT *)NULL )
  3679. -     error(E_NULL,"sub_mat");
  3680. -   if ( row1 > row2 || col1 > col2 || row2 >= old->m || col2 >= old->n )
  3681. -     error(E_RANGE,"sub_mat");
  3682. -   if ( new==(MAT *)NULL || new->m < row2-row1+1 )
  3683. -   {
  3684. -      new = NEW(MAT);
  3685. -      new->me = NEW_A(row2-row1+1,Real *);
  3686. -      if ( new==(MAT *)NULL || new->me==(Real **)NULL )
  3687. -    error(E_MEM,"sub_mat");
  3688. -      else if (mem_info_is_on()) {
  3689. -     mem_bytes(TYPE_MAT,0,sizeof(MAT)+
  3690. -              (row2-row1+1)*sizeof(Real *));
  3691. -      }
  3692. -      
  3693. -   }
  3694. -   new->m = row2-row1+1;
  3695. -   
  3696. -   new->n = col2-col1+1;
  3697. -   
  3698. -   new->base = (Real *)NULL;
  3699. -   
  3700. -   for ( i=0; i < new->m; i++ )
  3701. -     new->me[i] = (old->me[i+row1]) + col1;
  3702. -   
  3703. -   return (new);
  3704. -}
  3705. -
  3706. -
  3707. -/* sub_vec -- returns sub-vector which is formed by the elements i1 to i2
  3708. -   -- as for sub_mat, storage is shared */
  3709. -VEC    *sub_vec(old,i1,i2,new)
  3710. -VEC    *old, *new;
  3711. -int    i1, i2;
  3712. -{
  3713. -   if ( old == (VEC *)NULL )
  3714. -     error(E_NULL,"sub_vec");
  3715. -   if ( i1 > i2 || old->dim < i2 )
  3716. -     error(E_RANGE,"sub_vec");
  3717. -   
  3718. -   if ( new == (VEC *)NULL )
  3719. -     new = NEW(VEC);
  3720. -   if ( new == (VEC *)NULL )
  3721. -     error(E_MEM,"sub_vec");
  3722. -   else if (mem_info_is_on()) {
  3723. -      mem_bytes(TYPE_VEC,0,sizeof(VEC));
  3724. -   }
  3725. -   
  3726. -   
  3727. -   new->dim = i2 - i1 + 1;
  3728. -   new->ve = &(old->ve[i1]);
  3729. -   
  3730. -   return new;
  3731. -}
  3732. //GO.SYSIN DD submat.c
  3733. echo init.c 1>&2
  3734. sed >init.c <<'//GO.SYSIN DD init.c' 's/^-//'
  3735. -
  3736. -/**************************************************************************
  3737. -**
  3738. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  3739. -**
  3740. -**                 Meschach Library
  3741. -** 
  3742. -** This Meschach Library is provided "as is" without any express 
  3743. -** or implied warranty of any kind with respect to this software. 
  3744. -** In particular the authors shall not be liable for any direct, 
  3745. -** indirect, special, incidental or consequential damages arising 
  3746. -** in any way from use of the software.
  3747. -** 
  3748. -** Everyone is granted permission to copy, modify and redistribute this
  3749. -** Meschach Library, provided:
  3750. -**  1.  All copies contain this copyright notice.
  3751. -**  2.  All modified copies shall carry a notice stating who
  3752. -**      made the last modification and the date of such modification.
  3753. -**  3.  No charge is made for this software or works derived from it.  
  3754. -**      This clause shall not be construed as constraining other software
  3755. -**      distributed on the same medium as this software, nor is a
  3756. -**      distribution fee considered a charge.
  3757. -**
  3758. -***************************************************************************/
  3759. -
  3760. -
  3761. -/*
  3762. -    This is a file of routines for zero-ing, and initialising
  3763. -    vectors, matrices and permutations.
  3764. -    This is to be included in the matrix.a library
  3765. -*/
  3766. -
  3767. -static    char    rcsid[] = "$Id: init.c,v 1.6 1994/01/13 05:36:58 des Exp $";
  3768. -
  3769. -#include    <stdio.h>
  3770. -#include    "matrix.h"
  3771. -
  3772. -/* v_zero -- zero the vector x */
  3773. -VEC    *v_zero(x)
  3774. -VEC    *x;
  3775. -{
  3776. -    if ( x == VNULL )
  3777. -        error(E_NULL,"v_zero");
  3778. -
  3779. -    __zero__(x->ve,x->dim);
  3780. -    /* for ( i = 0; i < x->dim; i++ )
  3781. -        x->ve[i] = 0.0; */
  3782. -
  3783. -    return x;
  3784. -}
  3785. -
  3786. -
  3787. -/* iv_zero -- zero the vector ix */
  3788. -IVEC    *iv_zero(ix)
  3789. -IVEC    *ix;
  3790. -{
  3791. -   int i;
  3792. -   
  3793. -   if ( ix == IVNULL )
  3794. -     error(E_NULL,"iv_zero");
  3795. -   
  3796. -   for ( i = 0; i < ix->dim; i++ )
  3797. -     ix->ive[i] = 0; 
  3798. -   
  3799. -   return ix;
  3800. -}
  3801. -
  3802. -
  3803. -/* m_zero -- zero the matrix A */
  3804. -MAT    *m_zero(A)
  3805. -MAT    *A;
  3806. -{
  3807. -    int    i, A_m, A_n;
  3808. -    Real    **A_me;
  3809. -
  3810. -    if ( A == MNULL )
  3811. -        error(E_NULL,"m_zero");
  3812. -
  3813. -    A_m = A->m;    A_n = A->n;    A_me = A->me;
  3814. -    for ( i = 0; i < A_m; i++ )
  3815. -        __zero__(A_me[i],A_n);
  3816. -        /* for ( j = 0; j < A_n; j++ )
  3817. -            A_me[i][j] = 0.0; */
  3818. -
  3819. -    return A;
  3820. -}
  3821. -
  3822. -/* mat_id -- set A to being closest to identity matrix as possible
  3823. -    -- i.e. A[i][j] == 1 if i == j and 0 otherwise */
  3824. -MAT    *m_ident(A)
  3825. -MAT    *A;
  3826. -{
  3827. -    int    i, size;
  3828. -
  3829. -    if ( A == MNULL )
  3830. -        error(E_NULL,"m_ident");
  3831. -
  3832. -    m_zero(A);
  3833. -    size = min(A->m,A->n);
  3834. -    for ( i = 0; i < size; i++ )
  3835. -        A->me[i][i] = 1.0;
  3836. -
  3837. -    return A;
  3838. -}
  3839. -    
  3840. -/* px_ident -- set px to identity permutation */
  3841. -PERM    *px_ident(px)
  3842. -PERM    *px;
  3843. -{
  3844. -    int    i, px_size;
  3845. -    u_int    *px_pe;
  3846. -
  3847. -    if ( px == PNULL )
  3848. -        error(E_NULL,"px_ident");
  3849. -
  3850. -    px_size = px->size;    px_pe = px->pe;
  3851. -    for ( i = 0; i < px_size; i++ )
  3852. -        px_pe[i] = i;
  3853. -
  3854. -    return px;
  3855. -}
  3856. -
  3857. -/* Pseudo random number generator data structures */
  3858. -/* Knuth's lagged Fibonacci-based generator: See "Seminumerical Algorithms:
  3859. -   The Art of Computer Programming" sections 3.2-3.3 */
  3860. -
  3861. -#ifdef ANSI_C
  3862. -#ifndef LONG_MAX
  3863. -#include    <limits.h>
  3864. -#endif
  3865. -#endif
  3866. -
  3867. -#ifdef LONG_MAX
  3868. -#define MODULUS    LONG_MAX
  3869. -#else
  3870. -#define MODULUS    1000000000L    /* assuming long's at least 32 bits long */
  3871. -#endif
  3872. -#define MZ    0L
  3873. -
  3874. -static long mrand_list[56];
  3875. -static int  started = FALSE;
  3876. -static int  inext = 0, inextp = 31;
  3877. -
  3878. -
  3879. -/* mrand -- pseudo-random number generator */
  3880. -#ifdef ANSI_C
  3881. -double mrand(void)
  3882. -#else
  3883. -double mrand()
  3884. -#endif
  3885. -{
  3886. -    long    lval;
  3887. -    static Real  factor = 1.0/((Real)MODULUS);
  3888. -    
  3889. -    if ( ! started )
  3890. -    smrand(3127);
  3891. -    
  3892. -    inext = (inext >= 54) ? 0 : inext+1;
  3893. -    inextp = (inextp >= 54) ? 0 : inextp+1;
  3894. -
  3895. -    lval = mrand_list[inext]-mrand_list[inextp];
  3896. -    if ( lval < 0L )
  3897. -    lval += MODULUS;
  3898. -    mrand_list[inext] = lval;
  3899. -    
  3900. -    return (double)lval*factor;
  3901. -}
  3902. -
  3903. -/* mrandlist -- fills the array a[] with len random numbers */
  3904. -void    mrandlist(a, len)
  3905. -Real    a[];
  3906. -int    len;
  3907. -{
  3908. -    int        i;
  3909. -    long    lval;
  3910. -    static Real  factor = 1.0/((Real)MODULUS);
  3911. -    
  3912. -    if ( ! started )
  3913. -    smrand(3127);
  3914. -    
  3915. -    for ( i = 0; i < len; i++ )
  3916. -    {
  3917. -    inext = (inext >= 54) ? 0 : inext+1;
  3918. -    inextp = (inextp >= 54) ? 0 : inextp+1;
  3919. -    
  3920. -    lval = mrand_list[inext]-mrand_list[inextp];
  3921. -    if ( lval < 0L )
  3922. -        lval += MODULUS;
  3923. -    mrand_list[inext] = lval;
  3924. -    
  3925. -    a[i] = (Real)lval*factor;
  3926. -    }
  3927. -}
  3928. -
  3929. -
  3930. -/* smrand -- set seed for mrand() */
  3931. -void smrand(seed)
  3932. -int    seed;
  3933. -{
  3934. -    int        i;
  3935. -
  3936. -    mrand_list[0] = (123413*seed) % MODULUS;
  3937. -    for ( i = 1; i < 55; i++ )
  3938. -    mrand_list[i] = (123413*mrand_list[i-1]) % MODULUS;
  3939. -
  3940. -    started = TRUE;
  3941. -
  3942. -    /* run mrand() through the list sufficient times to
  3943. -       thoroughly randomise the array */
  3944. -    for ( i = 0; i < 55*55; i++ )
  3945. -    mrand();
  3946. -}
  3947. -#undef MODULUS
  3948. -#undef MZ
  3949. -#undef FAC
  3950. -
  3951. -/* v_rand -- initialises x to be a random vector, components
  3952. -    independently & uniformly ditributed between 0 and 1 */
  3953. -VEC    *v_rand(x)
  3954. -VEC    *x;
  3955. -{
  3956. -    /* int    i; */
  3957. -
  3958. -    if ( ! x )
  3959. -        error(E_NULL,"v_rand");
  3960. -
  3961. -    /* for ( i = 0; i < x->dim; i++ ) */
  3962. -        /* x->ve[i] = rand()/((Real)MAX_RAND); */
  3963. -        /* x->ve[i] = mrand(); */
  3964. -    mrandlist(x->ve,x->dim);
  3965. -
  3966. -    return x;
  3967. -}
  3968. -
  3969. -/* m_rand -- initialises A to be a random vector, components
  3970. -    independently & uniformly distributed between 0 and 1 */
  3971. -MAT    *m_rand(A)
  3972. -MAT    *A;
  3973. -{
  3974. -    int    i /* , j */;
  3975. -
  3976. -    if ( ! A )
  3977. -        error(E_NULL,"m_rand");
  3978. -
  3979. -    for ( i = 0; i < A->m; i++ )
  3980. -        /* for ( j = 0; j < A->n; j++ ) */
  3981. -            /* A->me[i][j] = rand()/((Real)MAX_RAND); */
  3982. -            /* A->me[i][j] = mrand(); */
  3983. -        mrandlist(A->me[i],A->n);
  3984. -
  3985. -    return A;
  3986. -}
  3987. -
  3988. -/* v_ones -- fills x with one's */
  3989. -VEC    *v_ones(x)
  3990. -VEC    *x;
  3991. -{
  3992. -    int    i;
  3993. -
  3994. -    if ( ! x )
  3995. -        error(E_NULL,"v_ones");
  3996. -
  3997. -    for ( i = 0; i < x->dim; i++ )
  3998. -        x->ve[i] = 1.0;
  3999. -
  4000. -    return x;
  4001. -}
  4002. -
  4003. -/* m_ones -- fills matrix with one's */
  4004. -MAT    *m_ones(A)
  4005. -MAT    *A;
  4006. -{
  4007. -    int    i, j;
  4008. -
  4009. -    if ( ! A )
  4010. -        error(E_NULL,"m_ones");
  4011. -
  4012. -    for ( i = 0; i < A->m; i++ )
  4013. -        for ( j = 0; j < A->n; j++ )
  4014. -            A->me[i][j] = 1.0;
  4015. -
  4016. -    return A;
  4017. -}
  4018. -
  4019. -/* v_count -- initialises x so that x->ve[i] == i */
  4020. -VEC    *v_count(x)
  4021. -VEC    *x;
  4022. -{
  4023. -    int    i;
  4024. -
  4025. -    if ( ! x )
  4026. -        error(E_NULL,"v_count");
  4027. -
  4028. -    for ( i = 0; i < x->dim; i++ )
  4029. -        x->ve[i] = (Real)i;
  4030. -
  4031. -    return x;
  4032. -}
  4033. //GO.SYSIN DD init.c
  4034. echo otherio.c 1>&2
  4035. sed >otherio.c <<'//GO.SYSIN DD otherio.c' 's/^-//'
  4036. -
  4037. -/**************************************************************************
  4038. -**
  4039. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  4040. -**
  4041. -**                 Meschach Library
  4042. -** 
  4043. -** This Meschach Library is provided "as is" without any express 
  4044. -** or implied warranty of any kind with respect to this software. 
  4045. -** In particular the authors shall not be liable for any direct, 
  4046. -** indirect, special, incidental or consequential damages arising 
  4047. -** in any way from use of the software.
  4048. -** 
  4049. -** Everyone is granted permission to copy, modify and redistribute this
  4050. -** Meschach Library, provided:
  4051. -**  1.  All copies contain this copyright notice.
  4052. -**  2.  All modified copies shall carry a notice stating who
  4053. -**      made the last modification and the date of such modification.
  4054. -**  3.  No charge is made for this software or works derived from it.  
  4055. -**      This clause shall not be construed as constraining other software
  4056. -**      distributed on the same medium as this software, nor is a
  4057. -**      distribution fee considered a charge.
  4058. -**
  4059. -***************************************************************************/
  4060. -
  4061. -
  4062. -/*
  4063. -    File for doing assorted I/O operations not invlolving
  4064. -    MAT/VEC/PERM objects
  4065. -*/
  4066. -static    char    rcsid[] = "$Id: otherio.c,v 1.2 1994/01/13 05:34:52 des Exp $";
  4067. -
  4068. -#include    <stdio.h>
  4069. -#include    <ctype.h>
  4070. -#include    "matrix.h"
  4071. -
  4072. -
  4073. -
  4074. -/* scratch area -- enough for a single line */
  4075. -static    char    scratch[MAXLINE+1];
  4076. -
  4077. -/* default value for fy_or_n */
  4078. -static    int    y_n_dflt = TRUE;
  4079. -
  4080. -/* fy_or_n -- yes-or-no to question is string s
  4081. -    -- question written to stderr, input from fp 
  4082. -    -- if fp is NOT a tty then return y_n_dflt */
  4083. -int    fy_or_n(fp,s)
  4084. -FILE    *fp;
  4085. -char    *s;
  4086. -{
  4087. -    char    *cp;
  4088. -
  4089. -    if ( ! isatty(fileno(fp)) )
  4090. -        return y_n_dflt;
  4091. -
  4092. -    for ( ; ; )
  4093. -    {
  4094. -        fprintf(stderr,"%s (y/n) ? ",s);
  4095. -        if ( fgets(scratch,MAXLINE,fp)==NULL )
  4096. -            error(E_INPUT,"fy_or_n");
  4097. -        cp = scratch;
  4098. -        while ( isspace(*cp) )
  4099. -            cp++;
  4100. -        if ( *cp == 'y' || *cp == 'Y' )
  4101. -            return TRUE;
  4102. -        if ( *cp == 'n' || *cp == 'N' )
  4103. -            return FALSE;
  4104. -        fprintf(stderr,"Please reply with 'y' or 'Y' for yes ");
  4105. -        fprintf(stderr,"and 'n' or 'N' for no.\n");
  4106. -    }
  4107. -}
  4108. -
  4109. -/* yn_dflt -- sets the value of y_n_dflt to val */
  4110. -int    yn_dflt(val)
  4111. -int    val;
  4112. -{    return y_n_dflt = val;        }
  4113. -
  4114. -/* fin_int -- return integer read from file/stream fp
  4115. -    -- prompt s on stderr if fp is a tty
  4116. -    -- check that x lies between low and high: re-prompt if
  4117. -        fp is a tty, error exit otherwise
  4118. -    -- ignore check if low > high        */
  4119. -int    fin_int(fp,s,low,high)
  4120. -FILE    *fp;
  4121. -char    *s;
  4122. -int    low, high;
  4123. -{
  4124. -    int    retcode, x;
  4125. -
  4126. -    if ( ! isatty(fileno(fp)) )
  4127. -    {
  4128. -        skipjunk(fp);
  4129. -        if ( (retcode=fscanf(fp,"%d",&x)) == EOF )
  4130. -            error(E_INPUT,"fin_int");
  4131. -        if ( retcode <= 0 )
  4132. -            error(E_FORMAT,"fin_int");
  4133. -        if ( low <= high && ( x < low || x > high ) )
  4134. -            error(E_BOUNDS,"fin_int");
  4135. -        return x;
  4136. -    }
  4137. -
  4138. -    for ( ; ; )
  4139. -    {
  4140. -        fprintf(stderr,"%s: ",s);
  4141. -        if ( fgets(scratch,MAXLINE,stdin)==NULL )
  4142. -            error(E_INPUT,"fin_int");
  4143. -        retcode = sscanf(scratch,"%d",&x);
  4144. -        if ( ( retcode==1 && low > high ) ||
  4145. -                    ( x >= low && x <= high ) )
  4146. -            return x;
  4147. -        fprintf(stderr,"Please type an integer in range [%d,%d].\n",
  4148. -                            low,high);
  4149. -    }
  4150. -}
  4151. -
  4152. -
  4153. -/* fin_double -- return double read from file/stream fp
  4154. -    -- prompt s on stderr if fp is a tty
  4155. -    -- check that x lies between low and high: re-prompt if
  4156. -        fp is a tty, error exit otherwise
  4157. -    -- ignore check if low > high        */
  4158. -double    fin_double(fp,s,low,high)
  4159. -FILE    *fp;
  4160. -char    *s;
  4161. -double    low, high;
  4162. -{
  4163. -    Real    retcode, x;
  4164. -
  4165. -    if ( ! isatty(fileno(fp)) )
  4166. -    {
  4167. -        skipjunk(fp);
  4168. -#if REAL == DOUBLE
  4169. -        if ( (retcode=fscanf(fp,"%lf",&x)) == EOF )
  4170. -#elif REAL == FLOAT
  4171. -        if ( (retcode=fscanf(fp,"%f",&x)) == EOF )
  4172. -#endif
  4173. -            error(E_INPUT,"fin_double");
  4174. -        if ( retcode <= 0 )
  4175. -            error(E_FORMAT,"fin_double");
  4176. -        if ( low <= high && ( x < low || x > high ) )
  4177. -            error(E_BOUNDS,"fin_double");
  4178. -        return (double)x;
  4179. -    }
  4180. -
  4181. -    for ( ; ; )
  4182. -    {
  4183. -        fprintf(stderr,"%s: ",s);
  4184. -        if ( fgets(scratch,MAXLINE,stdin)==NULL )
  4185. -            error(E_INPUT,"fin_double");
  4186. -#if REAL == DOUBLE
  4187. -        retcode = sscanf(scratch,"%lf",&x);
  4188. -#elif REAL == FLOAT 
  4189. -        retcode = sscanf(scratch,"%f",&x);
  4190. -#endif
  4191. -        if ( ( retcode==1 && low > high ) ||
  4192. -                    ( x >= low && x <= high ) )
  4193. -            return (double)x;
  4194. -        fprintf(stderr,"Please type an double in range [%g,%g].\n",
  4195. -                            low,high);
  4196. -    }
  4197. -}
  4198. -
  4199. -
  4200. //GO.SYSIN DD otherio.c
  4201. echo machine.c 1>&2
  4202. sed >machine.c <<'//GO.SYSIN DD machine.c' 's/^-//'
  4203. -
  4204. -/**************************************************************************
  4205. -**
  4206. -** Copyright (C) 1993 David E. Stewart & Zbigniew Leyk, all rights reserved.
  4207. -**
  4208. -**                 Meschach Library
  4209. -** 
  4210. -** This Meschach Library is provided "as is" without any express 
  4211. -** or implied warranty of any kind with respect to this software. 
  4212. -** In particular the authors shall not be liable for any direct, 
  4213. -** indirect, special, incidental or consequential damages arising 
  4214. -** in any way from use of the software.
  4215. -** 
  4216. -** Everyone is granted permission to copy, modify and redistribute this
  4217. -** Meschach Library, provided:
  4218. -**  1.  All copies contain this copyright notice.
  4219. -**  2.  All modified copies shall carry a notice stating who
  4220. -**      made the last modification and the date of such modification.
  4221. -**  3.  No charge is made for this software or works derived from it.  
  4222. -**      This clause shall not be construed as constraining other software
  4223. -**      distributed on the same medium as this software, nor is a
  4224. -**      distribution fee considered a charge.
  4225. -**
  4226. -***************************************************************************/
  4227. -
  4228. -/*
  4229. -  This file contains basic routines which are used by the functions
  4230. -  in meschach.a etc.
  4231. -  These are the routines that should be modified in order to take
  4232. -  full advantage of specialised architectures (pipelining, vector
  4233. -  processors etc).
  4234. -  */
  4235. -
  4236. -static    char    *rcsid = "$Id: machine.c,v 1.4 1994/01/13 05:28:56 des Exp $";
  4237. -
  4238. -#include    "machine.h"
  4239. -
  4240. -/* __ip__ -- inner product */
  4241. -double    __ip__(dp1,dp2,len)
  4242. -register Real    *dp1, *dp2;
  4243. -int    len;
  4244. -{
  4245. -#ifdef VUNROLL
  4246. -    register int    len4;
  4247. -    register Real    sum1, sum2, sum3;
  4248. -#endif
  4249. -    register int    i;
  4250. -    register Real     sum;
  4251. -
  4252. -    sum = 0.0;
  4253. -#ifdef VUNROLL
  4254. -    sum1 = sum2 = sum3 = 0.0;
  4255. -    
  4256. -    len4 = len / 4;
  4257. -    len  = len % 4;
  4258. -    
  4259. -    for ( i = 0; i < len4; i++ )
  4260. -    {
  4261. -    sum  += dp1[4*i]*dp2[4*i];
  4262. -    sum1 += dp1[4*i+1]*dp2[4*i+1];
  4263. -    sum2 += dp1[4*i+2]*dp2[4*i+2];
  4264. -    sum3 += dp1[4*i+3]*dp2[4*i+3];
  4265. -    }
  4266. -    sum  += sum1 + sum2 + sum3;
  4267. -    dp1 += 4*len4;    dp2 += 4*len4;
  4268. -#endif
  4269. -    
  4270. -    for ( i = 0; i < len; i++ )
  4271. -    sum  += dp1[i]*dp2[i];
  4272. -    
  4273. -    return sum;
  4274. -}
  4275. -
  4276. -/* __mltadd__ -- scalar multiply and add c.f. v_mltadd() */
  4277. -void    __mltadd__(dp1,dp2,s,len)
  4278. -register Real    *dp1, *dp2;
  4279. -register double s;
  4280. -register int    len;
  4281. -{
  4282. -    register int    i;
  4283. -#ifdef VUNROLL
  4284. -    register int        len4;
  4285. -    
  4286. -    len4 = len / 4;
  4287. -    len  = len % 4;
  4288. -    for ( i = 0; i < len4; i++ )
  4289. -    {
  4290. -    dp1[4*i]   += s*dp2[4*i];
  4291. -    dp1[4*i+1] += s*dp2[4*i+1];
  4292. -    dp1[4*i+2] += s*dp2[4*i+2];
  4293. -    dp1[4*i+3] += s*dp2[4*i+3];
  4294. -    }
  4295. -    dp1 += 4*len4;    dp2 += 4*len4;
  4296. -#endif
  4297. -    
  4298. -    for ( i = 0; i < len; i++ )
  4299. -    dp1[i] += s*dp2[i];
  4300. -}
  4301. -
  4302. -/* __smlt__ scalar multiply array c.f. sv_mlt() */
  4303. -void    __smlt__(dp,s,out,len)
  4304. -register Real    *dp, *out;
  4305. -register double s;
  4306. -register int    len;
  4307. -{
  4308. -    register int    i;
  4309. -    for ( i = 0; i < len; i++ )
  4310. -    out[i] = s*dp[i];
  4311. -}
  4312. -
  4313. -/* __add__ -- add arrays c.f. v_add() */
  4314. -void    __add__(dp1,dp2,out,len)
  4315. -register Real    *dp1, *dp2, *out;
  4316. -register int    len;
  4317. -{
  4318. -    register int    i;
  4319. -    for ( i = 0; i < len; i++ )
  4320. -    out[i] = dp1[i] + dp2[i];
  4321. -}
  4322. -
  4323. -/* __sub__ -- subtract arrays c.f. v_sub() */
  4324. -void    __sub__(dp1,dp2,out,len)
  4325. -register Real    *dp1, *dp2, *out;
  4326. -register int    len;
  4327. -{
  4328. -    register int    i;
  4329. -    for ( i = 0; i < len; i++ )
  4330. -    out[i] = dp1[i] - dp2[i];
  4331. -}
  4332. -
  4333. -/* __zero__ -- zeros an array of floating point numbers */
  4334. -void    __zero__(dp,len)
  4335. -register Real    *dp;
  4336. -register int    len;
  4337. -{
  4338. -#ifdef CHAR0ISDBL0
  4339. -    /* if a floating point zero is equivalent to a string of nulls */
  4340. -    MEM_ZERO((char *)dp,len*sizeof(Real));
  4341. -#else
  4342. -    /* else, need to zero the array entry by entry */
  4343. -    int    i;
  4344. -    for ( i = 0; i < len; i++ )
  4345. -    dp[i] = 0.0;
  4346. -#endif
  4347. -}
  4348. -
  4349. //GO.SYSIN DD machine.c
  4350. echo matlab.c 1>&2
  4351. sed >matlab.c <<'//GO.SYSIN DD matlab.c' 's/^-//'
  4352. -
  4353. -/**************************************************************************
  4354. -**
  4355. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  4356. -**
  4357. -**                 Meschach Library
  4358. -** 
  4359. -** This Meschach Library is provided "as is" without any express 
  4360. -** or implied warranty of any kind with respect to this software. 
  4361. -** In particular the authors shall not be liable for any direct, 
  4362. -** indirect, special, incidental or consequential damages arising 
  4363. -** in any way from use of the software.
  4364. -** 
  4365. -** Everyone is granted permission to copy, modify and redistribute this
  4366. -** Meschach Library, provided:
  4367. -**  1.  All copies contain this copyright notice.
  4368. -**  2.  All modified copies shall carry a notice stating who
  4369. -**      made the last modification and the date of such modification.
  4370. -**  3.  No charge is made for this software or works derived from it.  
  4371. -**      This clause shall not be construed as constraining other software
  4372. -**      distributed on the same medium as this software, nor is a
  4373. -**      distribution fee considered a charge.
  4374. -**
  4375. -***************************************************************************/
  4376. -
  4377. -
  4378. -/*
  4379. -    This file contains routines for import/exporting data to/from
  4380. -        MATLAB. The main routines are:
  4381. -            MAT *m_save(FILE *fp,MAT *A,char *name)
  4382. -            VEC *v_save(FILE *fp,VEC *x,char *name)
  4383. -            MAT *m_load(FILE *fp,char **name)
  4384. -*/
  4385. -
  4386. -#include        <stdio.h>
  4387. -#include        "matrix.h"
  4388. -#include    "matlab.h"
  4389. -
  4390. -static char rcsid[] = "$Id: matlab.c,v 1.7 1994/01/13 05:30:09 des Exp $";
  4391. -
  4392. -/* m_save -- save matrix in ".mat" file for MATLAB
  4393. -    -- returns matrix to be saved */
  4394. -MAT     *m_save(fp,A,name)
  4395. -FILE    *fp;
  4396. -MAT     *A;
  4397. -char    *name;
  4398. -{
  4399. -    int     i;
  4400. -    matlab  mat;
  4401. -
  4402. -    if ( ! A )
  4403. -        error(E_NULL,"m_save");
  4404. -
  4405. -    mat.type = 1000*MACH_ID + 100*ORDER + 10*PRECISION + 0;
  4406. -    mat.m = A->m;
  4407. -    mat.n = A->n;
  4408. -    mat.imag = FALSE;
  4409. -    mat.namlen = (name == (char *)NULL) ? 1 : strlen(name)+1;
  4410. -
  4411. -    /* write header */
  4412. -    fwrite(&mat,sizeof(matlab),1,fp);
  4413. -    /* write name */
  4414. -    if ( name == (char *)NULL )
  4415. -        fwrite("",sizeof(char),1,fp);
  4416. -    else
  4417. -        fwrite(name,sizeof(char),(int)(mat.namlen),fp);
  4418. -    /* write actual data */
  4419. -    for ( i = 0; i < A->m; i++ )
  4420. -        fwrite(A->me[i],sizeof(Real),(int)(A->n),fp);
  4421. -
  4422. -    return A;
  4423. -}
  4424. -
  4425. -
  4426. -/* v_save -- save vector in ".mat" file for MATLAB
  4427. -    -- saves it as a row vector
  4428. -    -- returns vector to be saved */
  4429. -VEC     *v_save(fp,x,name)
  4430. -FILE    *fp;
  4431. -VEC     *x;
  4432. -char    *name;
  4433. -{
  4434. -    matlab  mat;
  4435. -
  4436. -    if ( ! x )
  4437. -        error(E_NULL,"v_save");
  4438. -
  4439. -    mat.type = 1000*MACH_ID + 100*ORDER + 10*PRECISION + 0;
  4440. -    mat.m = x->dim;
  4441. -    mat.n = 1;
  4442. -    mat.imag = FALSE;
  4443. -    mat.namlen = (name == (char *)NULL) ? 1 : strlen(name)+1;
  4444. -
  4445. -    /* write header */
  4446. -    fwrite(&mat,sizeof(matlab),1,fp);
  4447. -    /* write name */
  4448. -    if ( name == (char *)NULL )
  4449. -        fwrite("",sizeof(char),1,fp);
  4450. -    else
  4451. -        fwrite(name,sizeof(char),(int)(mat.namlen),fp);
  4452. -    /* write actual data */
  4453. -    fwrite(x->ve,sizeof(Real),(int)(x->dim),fp);
  4454. -
  4455. -    return x;
  4456. -}
  4457. -
  4458. -/* d_save -- save double in ".mat" file for MATLAB
  4459. -    -- saves it as a row vector
  4460. -    -- returns vector to be saved */
  4461. -double    d_save(fp,x,name)
  4462. -FILE    *fp;
  4463. -double    x;
  4464. -char    *name;
  4465. -{
  4466. -    matlab  mat;
  4467. -    Real x1 = x;
  4468. -
  4469. -    mat.type = 1000*MACH_ID + 100*ORDER + 10*PRECISION + 0;
  4470. -    mat.m = 1;
  4471. -    mat.n = 1;
  4472. -    mat.imag = FALSE;
  4473. -    mat.namlen = (name == (char *)NULL) ? 1 : strlen(name)+1;
  4474. -
  4475. -    /* write header */
  4476. -    fwrite(&mat,sizeof(matlab),1,fp);
  4477. -    /* write name */
  4478. -    if ( name == (char *)NULL )
  4479. -        fwrite("",sizeof(char),1,fp);
  4480. -    else
  4481. -        fwrite(name,sizeof(char),(int)(mat.namlen),fp);
  4482. -    /* write actual data */
  4483. -    fwrite(&x1,sizeof(Real),1,fp);
  4484. -
  4485. -    return x;
  4486. -}
  4487. -
  4488. -/* m_load -- loads in a ".mat" file variable as produced by MATLAB
  4489. -    -- matrix returned; imaginary parts ignored */
  4490. -MAT     *m_load(fp,name)
  4491. -FILE    *fp;
  4492. -char    **name;
  4493. -{
  4494. -    MAT     *A;
  4495. -    int     i;
  4496. -    int     m_flag, o_flag, p_flag, t_flag;
  4497. -    float   f_temp;
  4498. -    Real    d_temp;
  4499. -    matlab  mat;
  4500. -
  4501. -    if ( fread(&mat,sizeof(matlab),1,fp) != 1 )
  4502. -        error(E_FORMAT,"m_load");
  4503. -    if ( mat.type >= 10000 )    /* don't load a sparse matrix! */
  4504. -        error(E_FORMAT,"m_load");
  4505. -    m_flag = (mat.type/1000) % 10;
  4506. -    o_flag = (mat.type/100) % 10;
  4507. -    p_flag = (mat.type/10) % 10;
  4508. -    t_flag = (mat.type) % 10;
  4509. -    if ( m_flag != MACH_ID )
  4510. -        error(E_FORMAT,"m_load");
  4511. -    if ( t_flag != 0 )
  4512. -        error(E_FORMAT,"m_load");
  4513. -    if ( p_flag != DOUBLE_PREC && p_flag != SINGLE_PREC )
  4514. -        error(E_FORMAT,"m_load");
  4515. -    *name = (char *)malloc((unsigned)(mat.namlen)+1);
  4516. -    if ( fread(*name,sizeof(char),(unsigned)(mat.namlen),fp) == 0 )
  4517. -        error(E_FORMAT,"m_load");
  4518. -    A = m_get((unsigned)(mat.m),(unsigned)(mat.n));
  4519. -    for ( i = 0; i < A->m*A->n; i++ )
  4520. -    {
  4521. -        if ( p_flag == DOUBLE_PREC )
  4522. -            fread(&d_temp,sizeof(double),1,fp);
  4523. -        else
  4524. -        {
  4525. -            fread(&f_temp,sizeof(float),1,fp);
  4526. -            d_temp = f_temp;
  4527. -        }
  4528. -        if ( o_flag == ROW_ORDER )
  4529. -            A->me[i / A->n][i % A->n] = d_temp;
  4530. -        else if ( o_flag == COL_ORDER )
  4531. -            A->me[i % A->m][i / A->m] = d_temp;
  4532. -        else
  4533. -            error(E_FORMAT,"m_load");
  4534. -    }
  4535. -
  4536. -    if ( mat.imag )         /* skip imaginary part */
  4537. -    for ( i = 0; i < A->m*A->n; i++ )
  4538. -    {
  4539. -        if ( p_flag == DOUBLE_PREC )
  4540. -            fread(&d_temp,sizeof(double),1,fp);
  4541. -        else
  4542. -            fread(&f_temp,sizeof(float),1,fp);
  4543. -    }
  4544. -
  4545. -    return A;
  4546. -}
  4547. -
  4548. //GO.SYSIN DD matlab.c
  4549. echo ivecop.c 1>&2
  4550. sed >ivecop.c <<'//GO.SYSIN DD ivecop.c' 's/^-//'
  4551. -
  4552. -/**************************************************************************
  4553. -**
  4554. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  4555. -**
  4556. -**                 Meschach Library
  4557. -** 
  4558. -** This Meschach Library is provided "as is" without any express 
  4559. -** or implied warranty of any kind with respect to this software. 
  4560. -** In particular the authors shall not be liable for any direct, 
  4561. -** indirect, special, incidental or consequential damages arising 
  4562. -** in any way from use of the software.
  4563. -** 
  4564. -** Everyone is granted permission to copy, modify and redistribute this
  4565. -** Meschach Library, provided:
  4566. -**  1.  All copies contain this copyright notice.
  4567. -**  2.  All modified copies shall carry a notice stating who
  4568. -**      made the last modification and the date of such modification.
  4569. -**  3.  No charge is made for this software or works derived from it.  
  4570. -**      This clause shall not be construed as constraining other software
  4571. -**      distributed on the same medium as this software, nor is a
  4572. -**      distribution fee considered a charge.
  4573. -**
  4574. -***************************************************************************/
  4575. -
  4576. -
  4577. -/* ivecop.c  */
  4578. -
  4579. -#include    <stdio.h>
  4580. -#include     "matrix.h"
  4581. -
  4582. -static    char    rcsid[] = "$Id: ivecop.c,v 1.5 1994/01/13 05:45:30 des Exp $";
  4583. -
  4584. -static char    line[MAXLINE];
  4585. -
  4586. -
  4587. -
  4588. -/* iv_get -- get integer vector -- see also memory.c */
  4589. -IVEC    *iv_get(dim)
  4590. -int    dim;
  4591. -{
  4592. -   IVEC    *iv;
  4593. -   /* u_int    i; */
  4594. -   
  4595. -   if (dim < 0)
  4596. -     error(E_NEG,"iv_get");
  4597. -
  4598. -   if ((iv=NEW(IVEC)) == IVNULL )
  4599. -     error(E_MEM,"iv_get");
  4600. -   else if (mem_info_is_on()) {
  4601. -      mem_bytes(TYPE_IVEC,0,sizeof(IVEC));
  4602. -      mem_numvar(TYPE_IVEC,1);
  4603. -   }
  4604. -   
  4605. -   iv->dim = iv->max_dim = dim;
  4606. -   if ((iv->ive = NEW_A(dim,int)) == (int *)NULL )
  4607. -     error(E_MEM,"iv_get");
  4608. -   else if (mem_info_is_on()) {
  4609. -      mem_bytes(TYPE_IVEC,0,dim*sizeof(int));
  4610. -   }
  4611. -   
  4612. -   return (iv);
  4613. -}
  4614. -
  4615. -/* iv_free -- returns iv & asoociated memory back to memory heap */
  4616. -int    iv_free(iv)
  4617. -IVEC    *iv;
  4618. -{
  4619. -   if ( iv==IVNULL || iv->dim > MAXDIM )
  4620. -     /* don't trust it */
  4621. -     return (-1);
  4622. -   
  4623. -   if ( iv->ive == (int *)NULL ) {
  4624. -      if (mem_info_is_on()) {
  4625. -     mem_bytes(TYPE_IVEC,sizeof(IVEC),0);
  4626. -     mem_numvar(TYPE_IVEC,-1);
  4627. -      }
  4628. -      free((char *)iv);
  4629. -   }
  4630. -   else
  4631. -   {
  4632. -      if (mem_info_is_on()) {
  4633. -     mem_bytes(TYPE_IVEC,sizeof(IVEC)+iv->max_dim*sizeof(int),0);
  4634. -     mem_numvar(TYPE_IVEC,-1);
  4635. -      }    
  4636. -      free((char *)iv->ive);
  4637. -      free((char *)iv);
  4638. -   }
  4639. -   
  4640. -   return (0);
  4641. -}
  4642. -
  4643. -/* iv_resize -- returns the IVEC with dimension new_dim
  4644. -   -- iv is set to the zero vector */
  4645. -IVEC    *iv_resize(iv,new_dim)
  4646. -IVEC    *iv;
  4647. -int    new_dim;
  4648. -{
  4649. -   int    i;
  4650. -   
  4651. -   if (new_dim < 0)
  4652. -     error(E_NEG,"iv_resize");
  4653. -
  4654. -   if ( ! iv )
  4655. -     return iv_get(new_dim);
  4656. -   
  4657. -   if (new_dim == iv->dim)
  4658. -     return iv;
  4659. -
  4660. -   if ( new_dim > iv->max_dim )
  4661. -   {
  4662. -      if (mem_info_is_on()) {
  4663. -     mem_bytes(TYPE_IVEC,iv->max_dim*sizeof(int),
  4664. -              new_dim*sizeof(int));
  4665. -      }
  4666. -      iv->ive = RENEW(iv->ive,new_dim,int);
  4667. -      if ( ! iv->ive )
  4668. -    error(E_MEM,"iv_resize");
  4669. -      iv->max_dim = new_dim;
  4670. -   }
  4671. -   if ( iv->dim <= new_dim )
  4672. -     for ( i = iv->dim; i < new_dim; i++ )
  4673. -       iv->ive[i] = 0;
  4674. -   iv->dim = new_dim;
  4675. -   
  4676. -   return iv;
  4677. -}
  4678. -
  4679. -/* iv_copy -- copy integer vector in to out
  4680. -   -- out created/resized if necessary */
  4681. -IVEC    *iv_copy(in,out)
  4682. -IVEC    *in, *out;
  4683. -{
  4684. -   int        i;
  4685. -   
  4686. -   if ( ! in )
  4687. -     error(E_NULL,"iv_copy");
  4688. -   out = iv_resize(out,in->dim);
  4689. -   for ( i = 0; i < in->dim; i++ )
  4690. -     out->ive[i] = in->ive[i];
  4691. -   
  4692. -   return out;
  4693. -}
  4694. -
  4695. -/* iv_move -- move selected pieces of an IVEC
  4696. -    -- moves the length dim0 subvector with initial index i0
  4697. -       to the corresponding subvector of out with initial index i1
  4698. -    -- out is resized if necessary */
  4699. -IVEC    *iv_move(in,i0,dim0,out,i1)
  4700. -IVEC    *in, *out;
  4701. -int    i0, dim0, i1;
  4702. -{
  4703. -    if ( ! in )
  4704. -    error(E_NULL,"iv_move");
  4705. -    if ( i0 < 0 || dim0 < 0 || i1 < 0 ||
  4706. -     i0+dim0 > in->dim )
  4707. -    error(E_BOUNDS,"iv_move");
  4708. -
  4709. -    if ( (! out) || i1+dim0 > out->dim )
  4710. -    out = iv_resize(out,i1+dim0);
  4711. -
  4712. -    MEM_COPY(&(in->ive[i0]),&(out->ive[i1]),dim0*sizeof(int));
  4713. -
  4714. -    return out;
  4715. -}
  4716. -
  4717. -/* iv_add -- integer vector addition -- may be in-situ */
  4718. -IVEC    *iv_add(iv1,iv2,out)
  4719. -IVEC    *iv1,*iv2,*out;
  4720. -{
  4721. -   u_int    i;
  4722. -   int    *out_ive, *iv1_ive, *iv2_ive;
  4723. -   
  4724. -   if ( iv1==IVNULL || iv2==IVNULL )
  4725. -     error(E_NULL,"iv_add");
  4726. -   if ( iv1->dim != iv2->dim )
  4727. -     error(E_SIZES,"iv_add");
  4728. -   if ( out==IVNULL || out->dim != iv1->dim )
  4729. -     out = iv_resize(out,iv1->dim);
  4730. -   
  4731. -   out_ive = out->ive;
  4732. -   iv1_ive = iv1->ive;
  4733. -   iv2_ive = iv2->ive;
  4734. -   
  4735. -   for ( i = 0; i < iv1->dim; i++ )
  4736. -     out_ive[i] = iv1_ive[i] + iv2_ive[i];
  4737. -   
  4738. -   return (out);
  4739. -}
  4740. -
  4741. -
  4742. -
  4743. -/* iv_sub -- integer vector addition -- may be in-situ */
  4744. -IVEC    *iv_sub(iv1,iv2,out)
  4745. -IVEC    *iv1,*iv2,*out;
  4746. -{
  4747. -   u_int    i;
  4748. -   int    *out_ive, *iv1_ive, *iv2_ive;
  4749. -   
  4750. -   if ( iv1==IVNULL || iv2==IVNULL )
  4751. -     error(E_NULL,"iv_sub");
  4752. -   if ( iv1->dim != iv2->dim )
  4753. -     error(E_SIZES,"iv_sub");
  4754. -   if ( out==IVNULL || out->dim != iv1->dim )
  4755. -     out = iv_resize(out,iv1->dim);
  4756. -   
  4757. -   out_ive = out->ive;
  4758. -   iv1_ive = iv1->ive;
  4759. -   iv2_ive = iv2->ive;
  4760. -   
  4761. -   for ( i = 0; i < iv1->dim; i++ )
  4762. -     out_ive[i] = iv1_ive[i] - iv2_ive[i];
  4763. -   
  4764. -   return (out);
  4765. -}
  4766. -
  4767. -/* iv_foutput -- print a representation of iv on stream fp */
  4768. -void    iv_foutput(fp,iv)
  4769. -FILE    *fp;
  4770. -IVEC    *iv;
  4771. -{
  4772. -   int    i;
  4773. -   
  4774. -   fprintf(fp,"IntVector: ");
  4775. -   if ( iv == IVNULL )
  4776. -   {
  4777. -      fprintf(fp,"**** NULL ****\n");
  4778. -      return;
  4779. -   }
  4780. -   fprintf(fp,"dim: %d\n",iv->dim);
  4781. -   for ( i = 0; i < iv->dim; i++ )
  4782. -   {
  4783. -      if ( (i+1) % 8 )
  4784. -    fprintf(fp,"%8d ",iv->ive[i]);
  4785. -      else
  4786. -    fprintf(fp,"%8d\n",iv->ive[i]);
  4787. -   }
  4788. -   if ( i % 8 )
  4789. -     fprintf(fp,"\n");
  4790. -}
  4791. -
  4792. -
  4793. -/* iv_finput -- input integer vector from stream fp */
  4794. -IVEC    *iv_finput(fp,x)
  4795. -FILE    *fp;
  4796. -IVEC    *x;
  4797. -{
  4798. -   IVEC    *iiv_finput(),*biv_finput();
  4799. -   
  4800. -   if ( isatty(fileno(fp)) )
  4801. -     return iiv_finput(fp,x);
  4802. -   else
  4803. -     return biv_finput(fp,x);
  4804. -}
  4805. -
  4806. -/* iiv_finput -- interactive input of IVEC iv */
  4807. -IVEC    *iiv_finput(fp,iv)
  4808. -FILE    *fp;
  4809. -IVEC    *iv;
  4810. -{
  4811. -   u_int    i,dim,dynamic;    /* dynamic set if memory allocated here */
  4812. -   
  4813. -   /* get dimension */
  4814. -   if ( iv != (IVEC *)NULL && iv->dim<MAXDIM )
  4815. -   {    dim = iv->dim;    dynamic = FALSE;    }
  4816. -   else
  4817. -   {
  4818. -      dynamic = TRUE;
  4819. -      do
  4820. -      {
  4821. -     fprintf(stderr,"IntVector: dim: ");
  4822. -     if ( fgets(line,MAXLINE,fp)==NULL )
  4823. -       error(E_INPUT,"iiv_finput");
  4824. -      } while ( sscanf(line,"%u",&dim)<1 || dim>MAXDIM );
  4825. -      iv = iv_get(dim);
  4826. -   }
  4827. -   
  4828. -   /* input elements */
  4829. -   for ( i=0; i<dim; i++ )
  4830. -     do
  4831. -     {
  4832. -      redo:
  4833. -    fprintf(stderr,"entry %u: ",i);
  4834. -    if ( !dynamic )
  4835. -      fprintf(stderr,"old: %-9d  new: ",iv->ive[i]);
  4836. -    if ( fgets(line,MAXLINE,fp)==NULL )
  4837. -      error(E_INPUT,"iiv_finput");
  4838. -    if ( (*line == 'b' || *line == 'B') && i > 0 )
  4839. -    {    i--;    dynamic = FALSE;    goto redo;       }
  4840. -    if ( (*line == 'f' || *line == 'F') && i < dim-1 )
  4841. -    {    i++;    dynamic = FALSE;    goto redo;       }
  4842. -     } while ( *line=='\0' || sscanf(line,"%d",&iv->ive[i]) < 1 );
  4843. -   
  4844. -   return (iv);
  4845. -}
  4846. -
  4847. -/* biv_finput -- batch-file input of IVEC iv */
  4848. -IVEC    *biv_finput(fp,iv)
  4849. -FILE    *fp;
  4850. -IVEC    *iv;
  4851. -{
  4852. -   u_int    i,dim;
  4853. -   int    io_code;
  4854. -   
  4855. -   /* get dimension */
  4856. -   skipjunk(fp);
  4857. -   if ((io_code=fscanf(fp," IntVector: dim:%u",&dim)) < 1 ||
  4858. -       dim>MAXDIM )
  4859. -     error(io_code==EOF ? 7 : 6,"biv_finput");
  4860. -   
  4861. -   /* allocate memory if necessary */
  4862. -   if ( iv==(IVEC *)NULL || iv->dim<dim )
  4863. -     iv = iv_resize(iv,dim);
  4864. -   
  4865. -   /* get entries */
  4866. -   skipjunk(fp);
  4867. -   for ( i=0; i<dim; i++ )
  4868. -     if ((io_code=fscanf(fp,"%d",&iv->ive[i])) < 1 )
  4869. -       error(io_code==EOF ? 7 : 6,"biv_finput");
  4870. -   
  4871. -   return (iv);
  4872. -}
  4873. -
  4874. -/* iv_dump -- dumps all the contents of IVEC iv onto stream fp */
  4875. -void    iv_dump(fp,iv)
  4876. -FILE*fp;
  4877. -IVEC*iv;
  4878. -{
  4879. -   int        i;
  4880. -   
  4881. -   fprintf(fp,"IntVector: ");
  4882. -   if ( ! iv )
  4883. -   {
  4884. -      fprintf(fp,"**** NULL ****\n");
  4885. -      return;
  4886. -   }
  4887. -   fprintf(fp,"dim: %d, max_dim: %d\n",iv->dim,iv->max_dim);
  4888. -   fprintf(fp,"ive @ 0x%lx\n",(long)(iv->ive));
  4889. -   for ( i = 0; i < iv->max_dim; i++ )
  4890. -   {
  4891. -      if ( (i+1) % 8 )
  4892. -    fprintf(fp,"%8d ",iv->ive[i]);
  4893. -      else
  4894. -    fprintf(fp,"%8d\n",iv->ive[i]);
  4895. -   }
  4896. -   if ( i % 8 )
  4897. -     fprintf(fp,"\n");
  4898. -}    
  4899. -
  4900. -#define    MAX_STACK    60
  4901. -
  4902. -
  4903. -/* iv_sort -- sorts vector x, and generates permutation that gives the order
  4904. -   of the components; x = [1.3, 3.7, 0.5] -> [0.5, 1.3, 3.7] and
  4905. -   the permutation is order = [2, 0, 1].
  4906. -   -- if order is NULL on entry then it is ignored
  4907. -   -- the sorted vector x is returned */
  4908. -IVEC    *iv_sort(x, order)
  4909. -IVEC    *x;
  4910. -PERM    *order;
  4911. -{
  4912. -   int        *x_ive, tmp, v;
  4913. -   /* int        *order_pe; */
  4914. -   int        dim, i, j, l, r, tmp_i;
  4915. -   int        stack[MAX_STACK], sp;
  4916. -   
  4917. -   if ( ! x )
  4918. -     error(E_NULL,"v_sort");
  4919. -   if ( order != PNULL && order->size != x->dim )
  4920. -     order = px_resize(order, x->dim);
  4921. -   
  4922. -   x_ive = x->ive;
  4923. -   dim = x->dim;
  4924. -   if ( order != PNULL )
  4925. -     px_ident(order);
  4926. -   
  4927. -   if ( dim <= 1 )
  4928. -     return x;
  4929. -   
  4930. -   /* using quicksort algorithm in Sedgewick,
  4931. -      "Algorithms in C", Ch. 9, pp. 118--122 (1990) */
  4932. -   sp = 0;
  4933. -   l = 0;    r = dim-1;    v = x_ive[0];
  4934. -   for ( ; ; )
  4935. -   {
  4936. -      while ( r > l )
  4937. -      {
  4938. -     /* "i = partition(x_ive,l,r);" */
  4939. -     v = x_ive[r];
  4940. -     i = l-1;
  4941. -     j = r;
  4942. -     for ( ; ; )
  4943. -     {
  4944. -        while ( x_ive[++i] < v )
  4945. -          ;
  4946. -        while ( x_ive[--j] > v )
  4947. -          ;
  4948. -        if ( i >= j )    break;
  4949. -        
  4950. -        tmp = x_ive[i];
  4951. -        x_ive[i] = x_ive[j];
  4952. -        x_ive[j] = tmp;
  4953. -        if ( order != PNULL )
  4954. -        {
  4955. -           tmp_i = order->pe[i];
  4956. -           order->pe[i] = order->pe[j];
  4957. -           order->pe[j] = tmp_i;
  4958. -        }
  4959. -     }
  4960. -     tmp = x_ive[i];
  4961. -     x_ive[i] = x_ive[r];
  4962. -     x_ive[r] = tmp;
  4963. -     if ( order != PNULL )
  4964. -     {
  4965. -        tmp_i = order->pe[i];
  4966. -        order->pe[i] = order->pe[r];
  4967. -        order->pe[r] = tmp_i;
  4968. -     }
  4969. -     
  4970. -     if ( i-l > r-i )
  4971. -     {   stack[sp++] = l;   stack[sp++] = i-1;   l = i+1;   }
  4972. -     else
  4973. -     {   stack[sp++] = i+1;   stack[sp++] = r;   r = i-1;   }
  4974. -      }
  4975. -      
  4976. -      /* recursion elimination */
  4977. -      if ( sp == 0 )
  4978. -    break;
  4979. -      r = stack[--sp];
  4980. -      l = stack[--sp];
  4981. -   }
  4982. -   
  4983. -   return x;
  4984. -}
  4985. //GO.SYSIN DD ivecop.c
  4986. echo version.c 1>&2
  4987. sed >version.c <<'//GO.SYSIN DD version.c' 's/^-//'
  4988. -
  4989. -/**************************************************************************
  4990. -**
  4991. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  4992. -**
  4993. -**                 Meschach Library
  4994. -** 
  4995. -** This Meschach Library is provided "as is" without any express 
  4996. -** or implied warranty of any kind with respect to this software. 
  4997. -** In particular the authors shall not be liable for any direct, 
  4998. -** indirect, special, incidental or consequential damages arising 
  4999. -** in any way from use of the software.
  5000. -** 
  5001. -** Everyone is granted permission to copy, modify and redistribute this
  5002. -** Meschach Library, provided:
  5003. -**  1.  All copies contain this copyright notice.
  5004. -**  2.  All modified copies shall carry a notice stating who
  5005. -**      made the last modification and the date of such modification.
  5006. -**  3.  No charge is made for this software or works derived from it.  
  5007. -**      This clause shall not be construed as constraining other software
  5008. -**      distributed on the same medium as this software, nor is a
  5009. -**      distribution fee considered a charge.
  5010. -**
  5011. -***************************************************************************/
  5012. -
  5013. -
  5014. -/*            Version routine            */
  5015. -/*    This routine must be modified whenever modifications are made to
  5016. -    Meschach by persons other than the original authors
  5017. -    (David E. Stewart & Zbigniew Leyk); 
  5018. -    when new releases of Meschach are made the
  5019. -    version number will also be updated
  5020. -*/
  5021. -
  5022. -#include    <stdio.h>
  5023. -
  5024. -void    m_version()
  5025. -{
  5026. -    static char rcsid[] = "$Id: version.c,v 1.9 1994/03/24 00:04:05 des Exp $";
  5027. -
  5028. -    printf("Meshach matrix library version 1.2b\n");
  5029. -    printf("RCS id: %s\n",rcsid);
  5030. -    printf("Changes since 1.2a:\n");
  5031. -    printf("\t Fixed bug in schur() for 2x2 blocks with real e-vals\n");
  5032. -    printf("\t Fixed bug in schur() reading beyond end of array\n");
  5033. -    printf("\t Fixed some installation bugs\n");
  5034. -    printf("\t Fixed bugs & improved efficiency in spILUfactor()\n");
  5035. -    printf("\t px_inv() doesn't crash inverting non-permutations\n");
  5036. -    /**** List of modifications ****/
  5037. -    /* Example below is for illustration only */
  5038. -    /* printf("Modified by %s, routine(s) %s, file %s on date %s\n",
  5039. -            "Joe Bloggs",
  5040. -            "m_version",
  5041. -            "version.c",
  5042. -            "Fri Apr  5 16:00:38 EST 1994"); */
  5043. -    /* printf("Purpose: %s\n",
  5044. -            "To update the version number"); */
  5045. -}
  5046. -
  5047. -/* $Log: version.c,v $
  5048. - * Revision 1.9  1994/03/24  00:04:05  des
  5049. - * Added notes on changes to spILUfactor() and px_inv().
  5050. - *
  5051. - * Revision 1.8  1994/02/21  04:32:25  des
  5052. - * Set version to 1.2b with bug fixes in schur() and installation.
  5053. - *
  5054. - * Revision 1.7  1994/01/13  05:43:57  des
  5055. - * Version 1.2 update
  5056. - *
  5057. -
  5058. - * */
  5059. //GO.SYSIN DD version.c
  5060. echo meminfo.c 1>&2
  5061. sed >meminfo.c <<'//GO.SYSIN DD meminfo.c' 's/^-//'
  5062. -
  5063. -/**************************************************************************
  5064. -**
  5065. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  5066. -**
  5067. -**                 Meschach Library
  5068. -** 
  5069. -** This Meschach Library is provided "as is" without any express 
  5070. -** or implied warranty of any kind with respect to this software. 
  5071. -** In particular the authors shall not be liable for any direct, 
  5072. -** indirect, special, incidental or consequential damages arising 
  5073. -** in any way from use of the software.
  5074. -** 
  5075. -** Everyone is granted permission to copy, modify and redistribute this
  5076. -** Meschach Library, provided:
  5077. -**  1.  All copies contain this copyright notice.
  5078. -**  2.  All modified copies shall carry a notice stating who
  5079. -**      made the last modification and the date of such modification.
  5080. -**  3.  No charge is made for this software or works derived from it.  
  5081. -**      This clause shall not be construed as constraining other software
  5082. -**      distributed on the same medium as this software, nor is a
  5083. -**      distribution fee considered a charge.
  5084. -**
  5085. -***************************************************************************/
  5086. -
  5087. -
  5088. -/* meminfo.c  revised  22/11/93 */
  5089. -
  5090. -/* 
  5091. -  contains basic functions, types and arrays 
  5092. -  to keep track of memory allocation/deallocation
  5093. -*/
  5094. -
  5095. -#include <stdio.h>
  5096. -#include  "matrix.h"
  5097. -#include  "meminfo.h"
  5098. -#ifdef COMPLEX   
  5099. -#include  "zmatrix.h"
  5100. -#endif
  5101. -#ifdef SPARSE
  5102. -#include  "sparse.h"
  5103. -#include  "iter.h"
  5104. -#endif
  5105. -
  5106. -static char rcsid[] = "$Id: meminfo.c,v 1.1 1994/01/13 05:31:39 des Exp $";
  5107. -
  5108. -/* this array is defined further in this file */
  5109. -extern MEM_CONNECT mem_connect[MEM_CONNECT_MAX_LISTS];
  5110. -
  5111. -
  5112. -/* names of types */
  5113. -static char *mem_type_names[] = {
  5114. -   "MAT",
  5115. -   "BAND",
  5116. -   "PERM",
  5117. -   "VEC",
  5118. -   "IVEC"
  5119. -#ifdef SPARSE
  5120. -     ,"ITER",
  5121. -     "SPROW",
  5122. -     "SPMAT"
  5123. -#endif
  5124. -#ifdef COMPLEX   
  5125. -       ,"ZVEC",
  5126. -       "ZMAT"
  5127. -#endif
  5128. -      };
  5129. -
  5130. -
  5131. -#define MEM_NUM_STD_TYPES  (sizeof(mem_type_names)/sizeof(mem_type_names[0]))
  5132. -
  5133. -
  5134. -/* local array for keeping track of memory */
  5135. -static MEM_ARRAY   mem_info_sum[MEM_NUM_STD_TYPES];  
  5136. -
  5137. -
  5138. -/* for freeing various types */
  5139. -static int (*mem_free_funcs[MEM_NUM_STD_TYPES])() = {
  5140. -   m_free,
  5141. -   bd_free,
  5142. -   px_free,    
  5143. -   v_free,    
  5144. -   iv_free
  5145. -#ifdef SPARSE
  5146. -     ,iter_free,    
  5147. -     sprow_free, 
  5148. -     sp_free
  5149. -#endif
  5150. -#ifdef COMPLEX
  5151. -       ,zv_free,    
  5152. -       zm_free
  5153. -#endif
  5154. -      };
  5155. -
  5156. -
  5157. -
  5158. -/* it is a global variable for passing 
  5159. -   pointers to local arrays defined here */
  5160. -MEM_CONNECT mem_connect[MEM_CONNECT_MAX_LISTS] = {
  5161. - { mem_type_names, mem_free_funcs, MEM_NUM_STD_TYPES, 
  5162. -     mem_info_sum } 
  5163. -};
  5164. -
  5165. -
  5166. -/* attach a new list of types */
  5167. -
  5168. -int mem_attach_list(list, ntypes, type_names, free_funcs, info_sum)
  5169. -int list,ntypes;         /* number of a list and number of types there */
  5170. -char *type_names[];      /* list of names of types */
  5171. -int (*free_funcs[])();   /* list of releasing functions */
  5172. -MEM_ARRAY info_sum[];    /* local table */
  5173. -{
  5174. -   if (list < 0 || list >= MEM_CONNECT_MAX_LISTS)
  5175. -     return -1;
  5176. -
  5177. -   if (type_names == NULL || free_funcs == NULL 
  5178. -       || info_sum == NULL || ntypes < 0)
  5179. -     return -1;
  5180. -   
  5181. -   /* if a list exists do not overwrite */
  5182. -   if ( mem_connect[list].ntypes != 0 )
  5183. -     error(E_OVERWRITE,"mem_attach_list");
  5184. -   
  5185. -   mem_connect[list].ntypes = ntypes;
  5186. -   mem_connect[list].type_names = type_names;
  5187. -   mem_connect[list].free_funcs = free_funcs;
  5188. -   mem_connect[list].info_sum = info_sum;
  5189. -   return 0;
  5190. -}
  5191. -
  5192. -
  5193. -/* release a list of types */
  5194. -int mem_free_vars(list)
  5195. -int list;
  5196. -{    
  5197. -   if (list < 0 || list >= MEM_CONNECT_MAX_LISTS)
  5198. -     return -1;
  5199. -   
  5200. -   mem_connect[list].ntypes = 0;
  5201. -   mem_connect[list].type_names = NULL;
  5202. -   mem_connect[list].free_funcs = NULL;
  5203. -   mem_connect[list].info_sum = NULL;
  5204. -   
  5205. -   return 0;
  5206. -}
  5207. -
  5208. -
  5209. -
  5210. -/* check if list is attached */
  5211. -
  5212. -int mem_is_list_attached(list)
  5213. -int list;
  5214. -{
  5215. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS )
  5216. -   return FALSE;
  5217. -
  5218. -   if ( mem_connect[list].type_names != NULL &&
  5219. -        mem_connect[list].free_funcs != NULL &&
  5220. -        mem_connect[list].info_sum != NULL)
  5221. -     return TRUE;
  5222. -   else return FALSE;
  5223. -}
  5224. -
  5225. -/* to print out the contents of mem_connect[list] */
  5226. -
  5227. -void mem_dump_list(fp,list)
  5228. -FILE *fp;
  5229. -int list;
  5230. -{
  5231. -   int i;
  5232. -   MEM_CONNECT *mlist;
  5233. -
  5234. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS )
  5235. -     return;
  5236. -
  5237. -   mlist = &mem_connect[list];
  5238. -   fprintf(fp," %15s[%d]:\n","CONTENTS OF mem_connect",list);
  5239. -   fprintf(fp," %-7s   %-12s   %-9s   %s\n",
  5240. -       "name of",
  5241. -       "alloc.", "# alloc.",
  5242. -       "address"
  5243. -       );
  5244. -   fprintf(fp," %-7s   %-12s   %-9s   %s\n",
  5245. -       " type",
  5246. -       "bytes", "variables",
  5247. -       "of *_free()"
  5248. -       );
  5249. -
  5250. -   for (i=0; i < mlist->ntypes; i++) 
  5251. -     fprintf(fp,"  %-7s   %-12ld   %-9d   %p\n",
  5252. -         mlist->type_names[i], mlist->info_sum[i].bytes,
  5253. -         mlist->info_sum[i].numvar, mlist->free_funcs[i]
  5254. -         );
  5255. -   
  5256. -   fprintf(fp,"\n");
  5257. -}
  5258. -
  5259. -
  5260. -
  5261. -/*=============================================================*/
  5262. -
  5263. -
  5264. -/* local variables */
  5265. -
  5266. -static int    mem_switched_on = MEM_SWITCH_ON_DEF;  /* on/off */
  5267. -
  5268. -
  5269. -/* switch on/off memory info */
  5270. -
  5271. -int mem_info_on(sw)
  5272. -int sw;
  5273. -{
  5274. -   int old = mem_switched_on;
  5275. -   
  5276. -   mem_switched_on = sw;
  5277. -   return old;
  5278. -}
  5279. -
  5280. -#ifdef ANSI_C
  5281. -int mem_info_is_on(void)
  5282. -#else
  5283. -int mem_info_is_on()
  5284. -#endif
  5285. -{
  5286. -   return mem_switched_on;
  5287. -}
  5288. -
  5289. -
  5290. -/* information about allocated memory */
  5291. -
  5292. -/* return the number of allocated bytes for type 'type' */
  5293. -
  5294. -long mem_info_bytes(type,list)
  5295. -int type,list;
  5296. -{
  5297. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS )
  5298. -     return 0l;
  5299. -   if ( !mem_switched_on || type < 0 
  5300. -       || type >= mem_connect[list].ntypes
  5301. -       || mem_connect[list].free_funcs[type] == NULL )
  5302. -     return 0l;
  5303. -   
  5304. -   return mem_connect[list].info_sum[type].bytes;
  5305. -}
  5306. -
  5307. -/* return the number of allocated variables for type 'type' */
  5308. -int mem_info_numvar(type,list)
  5309. -int type,list;
  5310. -{
  5311. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS )
  5312. -     return 0l;
  5313. -   if ( !mem_switched_on || type < 0 
  5314. -       || type >= mem_connect[list].ntypes
  5315. -       || mem_connect[list].free_funcs[type] == NULL )
  5316. -     return 0l;
  5317. -   
  5318. -   return mem_connect[list].info_sum[type].numvar;
  5319. -}
  5320. -
  5321. -
  5322. -
  5323. -/* print out memory info to the file fp */
  5324. -void mem_info_file(fp,list)
  5325. -FILE *fp;
  5326. -int list;
  5327. -{
  5328. -   unsigned int type;
  5329. -   long t = 0l, d;
  5330. -   int n = 0, nt = 0;
  5331. -   MEM_CONNECT *mlist;
  5332. -   
  5333. -   if (!mem_switched_on) return;
  5334. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS )
  5335. -     return;
  5336. -   
  5337. -   if (list == 0)
  5338. -     fprintf(fp," MEMORY INFORMATION (standard types):\n");
  5339. -   else
  5340. -     fprintf(fp," MEMORY INFORMATION (list no. %d):\n",list);
  5341. -
  5342. -   mlist = &mem_connect[list];
  5343. -
  5344. -   for (type=0; type < mlist->ntypes; type++) {
  5345. -      if (mlist->type_names[type] == NULL ) continue;
  5346. -      d = mlist->info_sum[type].bytes;
  5347. -      t += d;
  5348. -      n = mlist->info_sum[type].numvar;
  5349. -      nt += n;
  5350. -      fprintf(fp," type %-7s %10ld alloc. byte%c  %6d alloc. variable%c\n",
  5351. -          mlist->type_names[type], d, (d!=1 ? 's' : ' '),
  5352. -          n, (n!=1 ? 's' : ' '));
  5353. -   }
  5354. -
  5355. -   fprintf(fp," %-12s %10ld alloc. byte%c  %6d alloc. variable%c\n\n",
  5356. -       "total:",t, (t!=1 ? 's' : ' '),
  5357. -       nt, (nt!=1 ? 's' : ' '));
  5358. -}
  5359. -
  5360. -
  5361. -/* function for memory information */
  5362. -
  5363. -
  5364. -/* mem_bytes_list
  5365. -   
  5366. -   Arguments:
  5367. -   type - the number of type;
  5368. -   old_size - old size of allocated memory (in bytes);
  5369. -   new_size - new size of allocated memory (in bytes);
  5370. -   list - list of types
  5371. -   */
  5372. -
  5373. -
  5374. -void mem_bytes_list(type,old_size,new_size,list)
  5375. -int type,list;
  5376. -int old_size,new_size;
  5377. -{
  5378. -   MEM_CONNECT *mlist;
  5379. -   
  5380. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS )
  5381. -     return;
  5382. -   
  5383. -   mlist = &mem_connect[list];
  5384. -   if (  type < 0 || type >= mlist->ntypes
  5385. -       || mlist->free_funcs[type] == NULL )
  5386. -     return;
  5387. -
  5388. -   if ( old_size < 0 || new_size < 0 )
  5389. -     error(E_NEG,"mem_bytes_list");
  5390. -
  5391. -   mlist->info_sum[type].bytes += new_size - old_size;
  5392. -   
  5393. -   /* check if the number of bytes is non-negative */
  5394. -   if ( old_size > 0 ) {
  5395. -
  5396. -      if (mlist->info_sum[type].bytes < 0)
  5397. -      {
  5398. -     fprintf(stderr,
  5399. -       "\n WARNING !! memory info: allocated memory is less than 0\n");
  5400. -     fprintf(stderr,"\t TYPE %s \n\n", mlist->type_names[type]);
  5401. -
  5402. -     if ( !isatty(fileno(stdout)) ) {
  5403. -        fprintf(stdout,
  5404. -          "\n WARNING !! memory info: allocated memory is less than 0\n");
  5405. -        fprintf(stdout,"\t TYPE %s \n\n", mlist->type_names[type]);
  5406. -     }
  5407. -      }
  5408. -   }
  5409. -}
  5410. -
  5411. -
  5412. -/* mem_numvar_list
  5413. -   
  5414. -   Arguments:
  5415. -   type - the number of type;
  5416. -   num - # of variables allocated (> 0) or deallocated ( < 0)
  5417. -   list - list of types
  5418. -   */
  5419. -
  5420. -
  5421. -void mem_numvar_list(type,num,list)
  5422. -int type,list,num;
  5423. -{
  5424. -   MEM_CONNECT *mlist;
  5425. -   
  5426. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS )
  5427. -     return;
  5428. -   
  5429. -   mlist = &mem_connect[list];
  5430. -   if (  type < 0 || type >= mlist->ntypes
  5431. -       || mlist->free_funcs[type] == NULL )
  5432. -     return;
  5433. -
  5434. -   mlist->info_sum[type].numvar += num;
  5435. -   
  5436. -   /* check if the number of variables is non-negative */
  5437. -   if ( num < 0 ) {
  5438. -
  5439. -      if (mlist->info_sum[type].numvar < 0)
  5440. -      {
  5441. -     fprintf(stderr,
  5442. -       "\n WARNING !! memory info: allocated # of variables is less than 0\n");
  5443. -     fprintf(stderr,"\t TYPE %s \n\n", mlist->type_names[type]);
  5444. -     if ( !isatty(fileno(stdout)) ) {
  5445. -        fprintf(stdout,
  5446. -      "\n WARNING !! memory info: allocated # of variables is less than 0\n");
  5447. -        fprintf(stdout,"\t TYPE %s \n\n", mlist->type_names[type]);
  5448. -     }
  5449. -      }
  5450. -   }
  5451. -}
  5452. -
  5453. //GO.SYSIN DD meminfo.c
  5454. echo memstat.c 1>&2
  5455. sed >memstat.c <<'//GO.SYSIN DD memstat.c' 's/^-//'
  5456. -
  5457. -/**************************************************************************
  5458. -**
  5459. -** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  5460. -**
  5461. -**                 Meschach Library
  5462. -** 
  5463. -** This Meschach Library is provided "as is" without any express 
  5464. -** or implied warranty of any kind with respect to this software. 
  5465. -** In particular the authors shall not be liable for any direct, 
  5466. -** indirect, special, incidental or consequential damages arising 
  5467. -** in any way from use of the software.
  5468. -** 
  5469. -** Everyone is granted permission to copy, modify and redistribute this
  5470. -** Meschach Library, provided:
  5471. -**  1.  All copies contain this copyright notice.
  5472. -**  2.  All modified copies shall carry a notice stating who
  5473. -**      made the last modification and the date of such modification.
  5474. -**  3.  No charge is made for this software or works derived from it.  
  5475. -**      This clause shall not be construed as constraining other software
  5476. -**      distributed on the same medium as this software, nor is a
  5477. -**      distribution fee considered a charge.
  5478. -**
  5479. -***************************************************************************/
  5480. -
  5481. -
  5482. -/*  mem_stat.c    6/09/93  */
  5483. -
  5484. -/* Deallocation of static arrays */
  5485. -
  5486. -
  5487. -#include <stdio.h>
  5488. -#include  "matrix.h"
  5489. -#include  "meminfo.h"
  5490. -#ifdef COMPLEX   
  5491. -#include  "zmatrix.h"
  5492. -#endif
  5493. -#ifdef SPARSE
  5494. -#include  "sparse.h"
  5495. -#include  "iter.h"
  5496. -#endif
  5497. -
  5498. -static char rcsid[] = "$Id: memstat.c,v 1.1 1994/01/13 05:32:44 des Exp $";
  5499. -
  5500. -/* global variable */
  5501. -
  5502. -extern MEM_CONNECT mem_connect[MEM_CONNECT_MAX_LISTS];
  5503. -
  5504. -
  5505. -/* local type */
  5506. -
  5507. -typedef struct {
  5508. -   void **var;    /* for &A, where A is a pointer */
  5509. -   int type;     /* type of A */
  5510. -   int mark;      /* what mark is chosen */
  5511. -} MEM_STAT_STRUCT;
  5512. -
  5513. -
  5514. -/* local variables */
  5515. -
  5516. -/* how many marks are used */
  5517. -static int mem_stat_mark_many = 0;
  5518. -
  5519. -/* current mark */
  5520. -static int mem_stat_mark_curr = 0;
  5521. -
  5522. -
  5523. -static MEM_STAT_STRUCT mem_stat_var[MEM_HASHSIZE];
  5524. -
  5525. -/* array of indices (+1) to mem_stat_var */
  5526. -static unsigned int mem_hash_idx[MEM_HASHSIZE];
  5527. -
  5528. -/* points to the first unused element in mem_hash_idx */
  5529. -static unsigned int mem_hash_idx_end = 0;
  5530. -
  5531. -
  5532. -
  5533. -/* hashing function */
  5534. -
  5535. -static unsigned int mem_hash(ptr)
  5536. -void **ptr;
  5537. -{
  5538. -   unsigned long lp = (unsigned long)ptr;
  5539. -
  5540. -   return (lp % MEM_HASHSIZE);
  5541. -}
  5542. -
  5543. -
  5544. -/* look for a place in mem_stat_var */
  5545. -static int mem_lookup(var)
  5546. -void **var;
  5547. -{
  5548. -   int k, j;
  5549. -
  5550. -   k = mem_hash(var);
  5551. -
  5552. -   if (mem_stat_var[k].var == var) {
  5553. -      return -1;
  5554. -   }
  5555. -   else if (mem_stat_var[k].var == NULL) {
  5556. -      return k;
  5557. -   }
  5558. -   else {  /* look for an empty place */
  5559. -      j = k;
  5560. -      while (mem_stat_var[j].var != var && j < MEM_HASHSIZE
  5561. -         && mem_stat_var[j].var != NULL) 
  5562. -    j++;
  5563. -
  5564. -      if (mem_stat_var[j].var == NULL) return j;
  5565. -      else if (mem_stat_var[j].var == var) return -1; 
  5566. -      else { /* if (j == MEM_HASHSIZE) */
  5567. -     j = 0;
  5568. -     while (mem_stat_var[j].var != var && j < k
  5569. -        && mem_stat_var[j].var != NULL) 
  5570. -       j++;
  5571. -     if (mem_stat_var[j].var == NULL) return j;
  5572. -     else if (mem_stat_var[j].var == var) return -1; 
  5573. -     else { /* if (j == k) */
  5574. -        fprintf(stderr,
  5575. -              "\n WARNING !!! static memory: mem_stat_var is too small\n");
  5576. -        fprintf(stderr,
  5577. -          " Increase MEM_HASHSIZE in file: %s (currently = %d)\n\n",
  5578. -            MEM_HASHSIZE_FILE, MEM_HASHSIZE);
  5579. -        if ( !isatty(fileno(stdout)) ) {
  5580. -           fprintf(stdout,
  5581. -                "\n WARNING !!! static memory: mem_stat_var is too small\n");
  5582. -           fprintf(stdout,
  5583. -            " Increase MEM_HASHSIZE in file: %s (currently = %d)\n\n",
  5584. -            MEM_HASHSIZE_FILE, MEM_HASHSIZE);
  5585. -        }
  5586. -        error(E_MEM,"mem_lookup");
  5587. -     }
  5588. -      }
  5589. -   }
  5590. -
  5591. -   return -1;
  5592. -}
  5593. -
  5594. -
  5595. -/* register static variables;
  5596. -   Input arguments:
  5597. -     var - variable to be registered,
  5598. -     type - type of this variable; 
  5599. -     list - list of types
  5600. -
  5601. -   returned value < 0  --> error,
  5602. -   returned value == 0 --> not registered,
  5603. -   returned value >= 0 --> registered with this mark;
  5604. -*/
  5605. -
  5606. -int mem_stat_reg_list(var,type,list)
  5607. -void **var;
  5608. -int type,list;
  5609. -{
  5610. -   int n;
  5611. -
  5612. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS )
  5613. -     return -1;
  5614. -
  5615. -   if (mem_stat_mark_curr == 0) return 0;  /* not registered */
  5616. -   if (var == NULL) return -1;             /* error */
  5617. -
  5618. -   if ( type < 0 || type >= mem_connect[list].ntypes || 
  5619. -       mem_connect[list].free_funcs[type] == NULL )
  5620. -   {
  5621. -      warning(WARN_WRONG_TYPE,"mem_stat_reg_list");
  5622. -      return -1;
  5623. -   }
  5624. -   
  5625. -   if ((n = mem_lookup(var)) >= 0) {
  5626. -      mem_stat_var[n].var = var;
  5627. -      mem_stat_var[n].mark = mem_stat_mark_curr;
  5628. -      mem_stat_var[n].type = type;
  5629. -      /* save n+1, not n */
  5630. -      mem_hash_idx[mem_hash_idx_end++] = n+1;
  5631. -   }
  5632. -
  5633. -   return mem_stat_mark_curr;
  5634. -}
  5635. -
  5636. -
  5637. -/* set a mark;
  5638. -   Input argument:
  5639. -   mark - positive number denoting a mark;
  5640. -   returned: 
  5641. -             mark if mark > 0,
  5642. -             0 if mark == 0,
  5643. -         -1 if mark is negative.
  5644. -*/
  5645. -
  5646. -int mem_stat_mark(mark)
  5647. -int mark;
  5648. -{
  5649. -   if (mark < 0) {
  5650. -      mem_stat_mark_curr = 0;
  5651. -      return -1;   /* error */
  5652. -   }
  5653. -   else if (mark == 0) {
  5654. -      mem_stat_mark_curr = 0; 
  5655. -      return 0; 
  5656. -   }
  5657. -
  5658. -   mem_stat_mark_curr = mark;
  5659. -   mem_stat_mark_many++;
  5660. -
  5661. -   return mark;
  5662. -}
  5663. -
  5664. -
  5665. -
  5666. -/* deallocate static variables;
  5667. -   Input argument:
  5668. -   mark - a positive number denoting the mark;
  5669. -
  5670. -   Returned:
  5671. -     -1 if mark < 0 (error);
  5672. -     0  if mark == 0;
  5673. -*/
  5674. -
  5675. -int mem_stat_free_list(mark,list)
  5676. -int mark,list;
  5677. -{
  5678. -   u_int i,j;
  5679. -   int     (*free_fn)();
  5680. -
  5681. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS 
  5682. -       || mem_connect[list].free_funcs == NULL )
  5683. -     return -1;
  5684. -
  5685. -   if (mark < 0) {
  5686. -      mem_stat_mark_curr = 0;
  5687. -      return -1;
  5688. -   }
  5689. -   else if (mark == 0) {
  5690. -      mem_stat_mark_curr = 0;
  5691. -      return 0;
  5692. -   }
  5693. -   
  5694. -   if (mem_stat_mark_many <= 0) {
  5695. -      warning(WARN_NO_MARK,"mem_stat_free");
  5696. -      return -1;
  5697. -   }
  5698. -
  5699. -   /* deallocate the marked variables */
  5700. -   for (i=0; i < mem_hash_idx_end; i++) {
  5701. -      j = mem_hash_idx[i];
  5702. -      if (j == 0) continue;
  5703. -      else {
  5704. -     j--;
  5705. -     if (mem_stat_var[j].mark == mark) {
  5706. -         free_fn = mem_connect[list].free_funcs[mem_stat_var[j].type];
  5707. -         if ( free_fn != NULL )
  5708. -         (*free_fn)(*mem_stat_var[j].var);
  5709. -         else
  5710. -         warning(WARN_WRONG_TYPE,"mem_stat_free");
  5711. -        
  5712. -        *(mem_stat_var[j].var) = NULL;
  5713. -        mem_stat_var[j].var = NULL;
  5714. -        mem_stat_var[j].mark = 0;
  5715. -        mem_hash_idx[i] = 0;
  5716. -     }
  5717. -      }
  5718. -   }
  5719. -
  5720. -   while (mem_hash_idx_end > 0 && mem_hash_idx[mem_hash_idx_end-1] == 0)
  5721. -     mem_hash_idx_end--;
  5722. -
  5723. -   mem_stat_mark_curr = 0;
  5724. -   mem_stat_mark_many--;
  5725. -   return 0;
  5726. -}
  5727. -
  5728. -
  5729. -/* only for diagnostic purposes */
  5730. -
  5731. -void mem_stat_dump(fp,list)
  5732. -FILE *fp;
  5733. -int list;
  5734. -{
  5735. -   u_int i,j,k=1;
  5736. -
  5737. -   if ( list < 0 || list >= MEM_CONNECT_MAX_LISTS 
  5738. -       || mem_connect[list].free_funcs == NULL )
  5739. -     return;
  5740. -
  5741. -   fprintf(fp," Array mem_stat_var (list no. %d):\n",list);
  5742. -   for (i=0; i < mem_hash_idx_end; i++) {
  5743. -      j = mem_hash_idx[i];
  5744. -      if (j == 0) continue;
  5745. -      else {
  5746. -     j--;
  5747. -     fprintf(fp," %d.  var = 0x%p, type = %s, mark = %d\n",
  5748. -         k,mem_stat_var[j].var,
  5749. -         mem_stat_var[j].type < mem_connect[list].ntypes &&
  5750. -         mem_connect[list].free_funcs[mem_stat_var[j].type] != NULL ?
  5751. -         mem_connect[list].type_names[(int)mem_stat_var[j].type] : 
  5752. -         "???",
  5753. -         mem_stat_var[j].mark);
  5754. -     k++;
  5755. -      }
  5756. -   }
  5757. -   
  5758. -   fprintf(fp,"\n");
  5759. -}
  5760. -
  5761. -
  5762. -/* query function about the current mark */
  5763. -#ifdef ANSI_C
  5764. -int mem_stat_show_mark(void)
  5765. -#else
  5766. -int mem_stat_show_mark()
  5767. -#endif
  5768. -{
  5769. -   return mem_stat_mark_curr;
  5770. -}
  5771. -
  5772. -
  5773. -/* Varying number of arguments */
  5774. -
  5775. -
  5776. -#ifdef ANSI_C
  5777. -
  5778. -/* To allocate memory to many arguments. 
  5779. -   The function should be called:
  5780. -   mem_stat_vars(list,type,&v1,&v2,&v3,...,VNULL);
  5781. -   where 
  5782. -     int list,type;
  5783. -     void **v1, **v2, **v3,...;
  5784. -     The last argument should be VNULL ! 
  5785. -     type is the type of variables v1,v2,v3,...
  5786. -     (of course they must be of the same type)
  5787. -*/
  5788. -
  5789. -int mem_stat_reg_vars(int list,int type,...)
  5790. -{
  5791. -   va_list ap;
  5792. -   int i=0;
  5793. -   void **par;
  5794. -   
  5795. -   va_start(ap, type);
  5796. -   while (par = va_arg(ap,void **)) {   /* NULL ends the list*/
  5797. -      mem_stat_reg_list(par,type,list);
  5798. -      i++;
  5799. -   } 
  5800. -
  5801. -   va_end(ap);
  5802. -   return i;
  5803. -}
  5804. -
  5805. -#elif VARARGS
  5806. -/* old varargs is used */
  5807. -
  5808. -/* To allocate memory to many arguments. 
  5809. -   The function should be called:
  5810. -   mem_stat_vars(list,type,&v1,&v2,&v3,...,VNULL);
  5811. -   where 
  5812. -     int list,type;
  5813. -     void **v1, **v2, **v3,...;
  5814. -     The last argument should be VNULL ! 
  5815. -     type is the type of variables v1,v2,v3,...
  5816. -     (of course they must be of the same type)
  5817. -*/
  5818. -
  5819. -int mem_stat_reg_vars(va_alist) va_dcl
  5820. -{
  5821. -   va_list ap;
  5822. -   int type,list,i=0;
  5823. -   void **par;
  5824. -   
  5825. -   va_start(ap);
  5826. -   list = va_arg(ap,int);
  5827. -   type = va_arg(ap,int);
  5828. -   while (par = va_arg(ap,void **)) {   /* NULL ends the list*/
  5829. -      mem_stat_reg_list(par,type,list);
  5830. -      i++;
  5831. -   } 
  5832. -
  5833. -   va_end(ap);
  5834. -   return i;
  5835. -}
  5836. -
  5837. -
  5838. -#endif
  5839. //GO.SYSIN DD memstat.c
  5840.